0 | module Idris.Env
 1 |
 2 | --- All environment variables accessed by the compiler are enumerated in this module.
 3 |
 4 | import public Data.List
 5 | import public Data.Maybe
 6 |
 7 | import System
 8 |
 9 | %default total
10 |
11 | ||| Environment variable used by Idris2 compiler
12 | public export
13 | record EnvDesc where
14 |   constructor MkEnvDesc
15 |   name : String
16 |   help : String
17 |
18 | ||| All environment variables used by Idris2 compiler
19 | public export
20 | envs : List EnvDesc
21 | envs = [
22 |     MkEnvDesc "EDITOR"               "Editor used in REPL :e command.",
23 |     MkEnvDesc "IDRIS2_PREFIX"        "Idris2 installation prefix.",
24 |     MkEnvDesc "IDRIS2_PATH"          "Directories where Idris2 looks for import files.",
25 |     MkEnvDesc "IDRIS2_PACKAGE_PATH"  "Directories where Idris2 looks for Idris 2 packages.",
26 |     MkEnvDesc "IDRIS2_DATA"          "Directories where Idris2 looks for data files.",
27 |     MkEnvDesc "IDRIS2_LIBS"          "Directories where Idris2 looks for libraries (for code generation).",
28 |     MkEnvDesc "IDRIS2_CG"            "Codegen backend.",
29 |     MkEnvDesc "IDRIS2_INC_CGS"       "Code generators to use (comma separated) when compiling modules incrementally.",
30 |     MkEnvDesc "CHEZ"                 "Chez backend: chez executable.",
31 |     MkEnvDesc "RACKET"               "Racket backend: racket executable.",
32 |     MkEnvDesc "RACKET_RACO"          "Racket backend: raco executable.",
33 |     MkEnvDesc "GAMBIT_GSI"           "Gambit backend: gsi executable.",
34 |     MkEnvDesc "GAMBIT_GSC"           "Gambit backend: gsc executable.",
35 |     MkEnvDesc "GAMBIT_GSC_BACKEND"   "Gambit backend: arguments passed to gsc.",
36 |     MkEnvDesc "IDRIS2_CC"            "RefC backend: C compiler executable.",
37 |     MkEnvDesc "IDRIS2_CFLAGS"        "RefC backend: C compiler flags.",
38 |     MkEnvDesc "IDRIS2_CPPFLAGS"      "RefC backend: C preprocessor flags.",
39 |     MkEnvDesc "IDRIS2_LDFLAGS"       "RefC backend: C linker flags.",
40 |     MkEnvDesc "IDRIS2_LDLIBS"        "RefC backend: C linker library names or flags.",
41 |     MkEnvDesc "CC"                   "RefC backend: C compiler executable (IDRIS2_CC takes precedence).",
42 |     MkEnvDesc "CFLAGS"               "RefC backend: C compiler flags (IDRIS2_CFLAGS takes precedence).",
43 |     MkEnvDesc "CPPFLAGS"             "RefC backend: C preprocessor flags (IDRIS2_CPPFLAGS takes precedence).",
44 |     MkEnvDesc "LDFLAGS"              "RefC backend: C linker flags (IDRIS2_LDFLAGS takes precedence).",
45 |     MkEnvDesc "LDLIBS"               "RefC backend: C linker library names or flags (IDRIS2_LDLIBS takes precedence).",
46 |     MkEnvDesc "NODE"                 "NodeJS backend: NodeJS executable.",
47 |     MkEnvDesc "PATH"                 "PATH variable is used to search for executables in certain codegens.",
48 |     MkEnvDesc "NO_COLOR"             "Instruct Idris not to print color to stdout. Passing the --color/--colour option will supersede this env var."]
49 |
50 | --- `public export` only for `auto` to work in `idrisGetEnv`
51 | public export
52 | envNames : List String
53 | envNames = map (.name) envs
54 |
55 | ||| Query documented environment variable
56 | public export
57 | idrisGetEnv : HasIO io => (name : String) ->
58 |   {auto 0 known : IsJust (find (name ==) Env.envNames)}
59 |   -> io (Maybe String)
60 | idrisGetEnv name = getEnv name
61 |