Merge pull request #203 from m-bd/path-lookup

Add PATH lookup to find Chez Scheme
This commit is contained in:
Edwin Brady 2020-03-05 10:17:33 +00:00 committed by GitHub
commit f38dd50b3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 11 deletions

View File

@ -19,14 +19,20 @@ import System.Info
%default covering
pathLookup : IO String
pathLookup
= do path <- getEnv "PATH"
let pathList = split (== ':') $ fromMaybe "/usr/bin:/usr/local/bin" path
let candidates = [p ++ "/" ++ x | p <- pathList,
x <- ["chez", "chezscheme9.5", "scheme"]]
e <- firstExists candidates
pure $ fromMaybe "/usr/bin/env scheme" e
findChez : IO String
findChez
= do env <- getEnv "CHEZ"
case env of
Just n => pure n
Nothing => do e <- firstExists [p ++ x | p <- ["/usr/bin/", "/usr/local/bin/"],
x <- ["chez", "chezscheme9.5", "scheme"]]
pure $ fromMaybe "/usr/bin/env scheme" e
= do Just chez <- getEnv "CHEZ" | Nothing => pathLookup
pure chez
-- Given the chez compiler directives, return a list of pairs of:
-- - the library file name

View File

@ -145,13 +145,18 @@ firstExists : List String -> IO (Maybe String)
firstExists [] = pure Nothing
firstExists (x :: xs) = if !(exists x) then pure (Just x) else firstExists xs
pathLookup : IO (Maybe String)
pathLookup = do
path <- getEnv "PATH"
let pathList = split (== ':') $ fromMaybe "/usr/bin:/usr/local/bin" path
let candidates = [p ++ "/" ++ x | p <- pathList,
x <- ["chez", "chezscheme9.5", "scheme"]]
firstExists candidates
findChez : IO (Maybe String)
findChez
= do env <- getEnv "CHEZ"
case env of
Just n => pure $ Just n
Nothing => firstExists [p ++ x | p <- ["/usr/bin/", "/usr/local/bin/"],
x <- ["chez", "chezscheme9.5", "scheme"]]
= do Just chez <- getEnv "CHEZ" | Nothing => pathLookup
pure $ Just chez
runChezTests : String -> List String -> IO (List Bool)
runChezTests prog tests