Remove uppercase vars in dune files
While maintaing them in jbuild files (with proper error messages) Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This commit is contained in:
parent
3348b6a913
commit
90cde684e6
|
@ -46,6 +46,7 @@ type t =
|
||||||
; stanzas_to_consider_for_install : Installable.t list
|
; stanzas_to_consider_for_install : Installable.t list
|
||||||
; cxx_flags : string list
|
; cxx_flags : string list
|
||||||
; vars : Value.t list String.Map.t
|
; vars : Value.t list String.Map.t
|
||||||
|
; uppercase_vars : Value.t list String.Map.t
|
||||||
; chdir : (Action.t, Action.t) Build.t
|
; chdir : (Action.t, Action.t) Build.t
|
||||||
; host : t option
|
; host : t option
|
||||||
; libs_by_package : (Package.t * Lib.Set.t) Package.Name.Map.t
|
; libs_by_package : (Package.t * Lib.Set.t) Package.Name.Map.t
|
||||||
|
@ -84,7 +85,19 @@ let installed_libs t = t.installed_libs
|
||||||
let find_scope_by_dir t dir = Scope.DB.find_by_dir t.scopes dir
|
let find_scope_by_dir t dir = Scope.DB.find_by_dir t.scopes dir
|
||||||
let find_scope_by_name t name = Scope.DB.find_by_name t.scopes name
|
let find_scope_by_name t name = Scope.DB.find_by_name t.scopes name
|
||||||
|
|
||||||
let expand_var_no_root t var = String.Map.find t.vars var
|
let expand_var_no_root t loc syntax_version var =
|
||||||
|
match String.Map.find t.vars var with
|
||||||
|
| Some _ as v -> v
|
||||||
|
| None ->
|
||||||
|
begin match String.Map.find t.uppercase_vars var with
|
||||||
|
| None -> None
|
||||||
|
| Some _ as v ->
|
||||||
|
if syntax_version < (1, 0) then
|
||||||
|
v
|
||||||
|
else
|
||||||
|
Loc.fail loc "Uppercase variables are removed in dune files. Use: %%{%s}"
|
||||||
|
(String.lowercase var)
|
||||||
|
end
|
||||||
|
|
||||||
let (expand_vars, expand_vars_path) =
|
let (expand_vars, expand_vars_path) =
|
||||||
let expand t ~scope ~dir ?(extra_vars=String.Map.empty) s =
|
let expand t ~scope ~dir ?(extra_vars=String.Map.empty) s =
|
||||||
|
@ -101,7 +114,9 @@ let (expand_vars, expand_vars_path) =
|
||||||
| "project_root" when syntax_version >= (1, 0) ->
|
| "project_root" when syntax_version >= (1, 0) ->
|
||||||
Some [Value.Path (Scope.root scope)]
|
Some [Value.Path (Scope.root scope)]
|
||||||
| var ->
|
| var ->
|
||||||
(match expand_var_no_root t var with
|
(match
|
||||||
|
expand_var_no_root t (String_with_vars.Var.loc v) syntax_version var
|
||||||
|
with
|
||||||
| Some _ as x -> x
|
| Some _ as x -> x
|
||||||
| None -> String.Map.find extra_vars var))
|
| None -> String.Map.find extra_vars var))
|
||||||
in
|
in
|
||||||
|
@ -280,7 +295,7 @@ let create
|
||||||
List.filter context.ocamlc_cflags
|
List.filter context.ocamlc_cflags
|
||||||
~f:(fun s -> not (String.is_prefix s ~prefix:"-std="))
|
~f:(fun s -> not (String.is_prefix s ~prefix:"-std="))
|
||||||
in
|
in
|
||||||
let vars =
|
let (vars, uppercase_vars) =
|
||||||
let ocamlopt =
|
let ocamlopt =
|
||||||
match context.ocamlopt with
|
match context.ocamlopt with
|
||||||
| None -> Path.relative context.ocaml_bin "ocamlopt"
|
| None -> Path.relative context.ocaml_bin "ocamlopt"
|
||||||
|
@ -295,30 +310,38 @@ let create
|
||||||
in
|
in
|
||||||
let cflags = context.ocamlc_cflags in
|
let cflags = context.ocamlc_cflags in
|
||||||
let strings = Value.L.strings in
|
let strings = Value.L.strings in
|
||||||
|
let lowercased =
|
||||||
|
[ "cpp" , strings (context.c_compiler :: cflags @ ["-E"])
|
||||||
|
; "cc" , strings (context.c_compiler :: cflags)
|
||||||
|
; "cxx" , strings (context.c_compiler :: cxx_flags)
|
||||||
|
; "ocaml" , path context.ocaml
|
||||||
|
; "ocamlc" , path context.ocamlc
|
||||||
|
; "ocamlopt" , path ocamlopt
|
||||||
|
; "arch_sixtyfour" , string (string_of_bool context.arch_sixtyfour)
|
||||||
|
; "make" , make
|
||||||
|
] in
|
||||||
let vars =
|
let vars =
|
||||||
[ "-verbose" , []
|
lowercased
|
||||||
; "CPP" , strings (context.c_compiler :: cflags @ ["-E"])
|
@ [ "-verbose" , []
|
||||||
; "PA_CPP" , strings (context.c_compiler :: cflags
|
; "pa_cpp" , strings (context.c_compiler :: cflags
|
||||||
@ ["-undef"; "-traditional";
|
@ ["-undef"; "-traditional";
|
||||||
"-x"; "c"; "-E"])
|
"-x"; "c"; "-E"])
|
||||||
; "CC" , strings (context.c_compiler :: cflags)
|
; "ocaml_bin" , path context.ocaml_bin
|
||||||
; "CXX" , strings (context.c_compiler :: cxx_flags)
|
; "ocaml_version" , string context.version_string
|
||||||
; "ocaml_bin" , path context.ocaml_bin
|
; "ocaml_where" , string (Path.to_string context.stdlib_dir)
|
||||||
; "OCAML" , path context.ocaml
|
; "null" , string (Path.to_string Config.dev_null)
|
||||||
; "OCAMLC" , path context.ocamlc
|
; "ext_obj" , string context.ext_obj
|
||||||
; "OCAMLOPT" , path ocamlopt
|
; "ext_asm" , string context.ext_asm
|
||||||
; "ocaml_version" , string context.version_string
|
; "ext_lib" , string context.ext_lib
|
||||||
; "ocaml_where" , string (Path.to_string context.stdlib_dir)
|
; "ext_dll" , string context.ext_dll
|
||||||
; "ARCH_SIXTYFOUR" , string (string_of_bool context.arch_sixtyfour)
|
; "ext_exe" , string context.ext_exe
|
||||||
; "MAKE" , make
|
; "profile" , string context.profile
|
||||||
; "null" , string (Path.to_string Config.dev_null)
|
]
|
||||||
; "ext_obj" , string context.ext_obj
|
in
|
||||||
; "ext_asm" , string context.ext_asm
|
let uppercase_vars =
|
||||||
; "ext_lib" , string context.ext_lib
|
lowercased
|
||||||
; "ext_dll" , string context.ext_dll
|
|> List.map ~f:(fun (k, v) -> (String.uppercase k, v))
|
||||||
; "ext_exe" , string context.ext_exe
|
|> String.Map.of_list_exn
|
||||||
; "profile" , string context.profile
|
|
||||||
]
|
|
||||||
in
|
in
|
||||||
let vars =
|
let vars =
|
||||||
vars @
|
vars @
|
||||||
|
@ -331,9 +354,7 @@ let create
|
||||||
| Words x -> strings x
|
| Words x -> strings x
|
||||||
| Prog_and_args x -> strings (x.prog :: x.args)))
|
| Prog_and_args x -> strings (x.prog :: x.args)))
|
||||||
in
|
in
|
||||||
match String.Map.of_list vars with
|
(String.Map.of_list_exn vars, uppercase_vars)
|
||||||
| Ok x -> x
|
|
||||||
| Error _ -> assert false
|
|
||||||
in
|
in
|
||||||
let t =
|
let t =
|
||||||
{ context
|
{ context
|
||||||
|
@ -348,6 +369,7 @@ let create
|
||||||
; stanzas_to_consider_for_install
|
; stanzas_to_consider_for_install
|
||||||
; artifacts
|
; artifacts
|
||||||
; cxx_flags
|
; cxx_flags
|
||||||
|
; uppercase_vars
|
||||||
; vars
|
; vars
|
||||||
; chdir = Build.arr (fun (action : Action.t) ->
|
; chdir = Build.arr (fun (action : Action.t) ->
|
||||||
match action with
|
match action with
|
||||||
|
@ -743,7 +765,7 @@ module Action = struct
|
||||||
add_ddep acc ~key data
|
add_ddep acc ~key data
|
||||||
end
|
end
|
||||||
| _ ->
|
| _ ->
|
||||||
match expand_var_no_root sctx key with
|
match expand_var_no_root sctx loc syntax_version key with
|
||||||
| Some _ as x -> x
|
| Some _ as x -> x
|
||||||
| None -> String.Map.find extra_vars key
|
| None -> String.Map.find extra_vars key
|
||||||
in
|
in
|
||||||
|
|
Loading…
Reference in New Issue