Make all variables accessible in jbuild files
This commit is contained in:
parent
21a980a5d1
commit
cc845e5fdb
|
@ -694,8 +694,13 @@ Jbuilder supports the following variables:
|
|||
- ``null`` is ``/dev/null`` on Unix or ``nul`` on Windows
|
||||
- ``ext_obj``, ``ext_asm``, ``ext_lib``, ``ext_dll`` and ``ext_exe``
|
||||
are the file extension used for various artifacts
|
||||
- ``bytecomp_c_libraries`` and ``native_c_libraries`` are list of C libraries
|
||||
used by the OCaml runtimes
|
||||
- ``ocaml-config:v`` for every variable ``v`` in the output of
|
||||
``ocamlc -config``. Note that output Jbuilder processes the output
|
||||
of ``ocamlc -config`` in order to make it a bit more stable across
|
||||
versions, so the exact set of variables accessible this way might
|
||||
not be exactly the same as what you can see in the output of
|
||||
``ocamlc -config``. In particular, variables added in new versions
|
||||
of OCaml needs to be registered in Jbuilder before they can be used
|
||||
|
||||
In addition, ``(action ...)`` fields support the following special variables:
|
||||
|
||||
|
|
|
@ -144,32 +144,43 @@ let create
|
|||
let strings l = Strings (l , Split) in
|
||||
let string s = Strings ([s], Split) in
|
||||
let path p = Paths ([p], Split) in
|
||||
[ "-verbose" , Strings ([] (*"-verbose";*), Concat)
|
||||
; "CPP" , strings (context.c_compiler :: cflags @ ["-E"])
|
||||
; "PA_CPP" , strings (context.c_compiler :: cflags
|
||||
@ ["-undef"; "-traditional"; "-x"; "c"; "-E"])
|
||||
; "CC" , strings (context.c_compiler :: cflags)
|
||||
; "CXX" , strings (context.c_compiler :: cxx_flags)
|
||||
; "ocaml_bin" , path context.ocaml_bin
|
||||
; "OCAML" , path context.ocaml
|
||||
; "OCAMLC" , path context.ocamlc
|
||||
; "OCAMLOPT" , path ocamlopt
|
||||
; "ocaml_version" , string context.version_string
|
||||
; "ocaml_where" , string (Path.to_string context.stdlib_dir)
|
||||
; "ARCH_SIXTYFOUR" , string (string_of_bool context.arch_sixtyfour)
|
||||
; "MAKE" , make
|
||||
; "null" , string (Path.to_string Config.dev_null)
|
||||
; "ext_obj" , string context.ext_obj
|
||||
; "ext_asm" , string context.ext_asm
|
||||
; "ext_lib" , string context.ext_lib
|
||||
; "ext_dll" , string context.ext_dll
|
||||
; "ext_exe" , string context.ext_exe
|
||||
; "bytecomp_c_libraries", strings context.bytecomp_c_libraries
|
||||
; "native_c_libraries" , strings context.bytecomp_c_libraries
|
||||
]
|
||||
|> String_map.of_list
|
||||
|> function
|
||||
| Ok x -> x
|
||||
let vars =
|
||||
[ "-verbose" , Strings ([] (*"-verbose";*), Concat)
|
||||
; "CPP" , strings (context.c_compiler :: cflags @ ["-E"])
|
||||
; "PA_CPP" , strings (context.c_compiler :: cflags
|
||||
@ ["-undef"; "-traditional";
|
||||
"-x"; "c"; "-E"])
|
||||
; "CC" , strings (context.c_compiler :: cflags)
|
||||
; "CXX" , strings (context.c_compiler :: cxx_flags)
|
||||
; "ocaml_bin" , path context.ocaml_bin
|
||||
; "OCAML" , path context.ocaml
|
||||
; "OCAMLC" , path context.ocamlc
|
||||
; "OCAMLOPT" , path ocamlopt
|
||||
; "ocaml_version" , string context.version_string
|
||||
; "ocaml_where" , string (Path.to_string context.stdlib_dir)
|
||||
; "ARCH_SIXTYFOUR" , string (string_of_bool context.arch_sixtyfour)
|
||||
; "MAKE" , make
|
||||
; "null" , string (Path.to_string Config.dev_null)
|
||||
; "ext_obj" , string context.ext_obj
|
||||
; "ext_asm" , string context.ext_asm
|
||||
; "ext_lib" , string context.ext_lib
|
||||
; "ext_dll" , string context.ext_dll
|
||||
; "ext_exe" , string context.ext_exe
|
||||
]
|
||||
in
|
||||
let vars =
|
||||
vars @
|
||||
List.map (Ocaml_config.to_list context.ocaml_config) ~f:(fun (k, v) ->
|
||||
("ocaml-config:" ^ k,
|
||||
match (v : Ocaml_config.Value.t) with
|
||||
| Bool x -> string (string_of_bool x)
|
||||
| Int x -> string (string_of_int x)
|
||||
| String x -> string x
|
||||
| Words x -> strings x
|
||||
| Prog_and_args x -> strings (x.prog :: x.args)))
|
||||
in
|
||||
match String_map.of_list vars with
|
||||
| Ok x -> x
|
||||
| Error _ -> assert false
|
||||
in
|
||||
{ context
|
||||
|
|
Loading…
Reference in New Issue