Merge branch 'master' into rename-jbuilder-dune
This commit is contained in:
commit
503ebf8a43
|
@ -61,6 +61,24 @@ module Temp = struct
|
|||
dir
|
||||
end
|
||||
|
||||
module Flags = struct
|
||||
let extract_words = String.extract_words
|
||||
|
||||
let extract_comma_space_separated_words =
|
||||
String.extract_comma_space_separated_words
|
||||
|
||||
let extract_blank_separated_words = String.extract_blank_separated_words
|
||||
|
||||
let write_lines fname s =
|
||||
let path = Path.of_string fname in
|
||||
Io.write_lines path s
|
||||
|
||||
let write_sexp fname s =
|
||||
let path = Path.in_source fname in
|
||||
let sexp = Usexp.List (List.map s ~f:(fun s -> Usexp.Quoted_string s)) in
|
||||
Io.write_file path (Usexp.to_string sexp ~syntax:Dune)
|
||||
end
|
||||
|
||||
module Find_in_path = struct
|
||||
let path_sep =
|
||||
if Sys.win32 then
|
||||
|
@ -485,18 +503,13 @@ module Pkg_config = struct
|
|||
None
|
||||
end
|
||||
|
||||
let write_flags fname s =
|
||||
let path = Path.in_source fname in
|
||||
let sexp = Usexp.List (List.map s ~f:(fun s -> Usexp.Quoted_string s)) in
|
||||
Io.write_file path (Usexp.to_string sexp ~syntax:Dune)
|
||||
|
||||
let main ?(args=[]) ~name f =
|
||||
let ocamlc = ref (
|
||||
match Sys.getenv "DUNE_CONFIGURATOR" with
|
||||
| s -> Some s
|
||||
| exception Not_found ->
|
||||
die "Configurator scripts must be ran with jbuilder. \
|
||||
To manually run a script, use $ jbuilder exec."
|
||||
die "Configurator scripts must be run with Dune. \
|
||||
To manually run a script, use $ dune exec."
|
||||
) in
|
||||
let verbose = ref false in
|
||||
let dest_dir = ref None in
|
||||
|
|
|
@ -87,10 +87,32 @@ module Pkg_config : sig
|
|||
val query : t -> package:string -> package_conf option
|
||||
end with type configurator := t
|
||||
|
||||
val write_flags : string -> string list -> unit
|
||||
(** [write_flags fname s] write the list of strings [s] to the file
|
||||
[fname] in an appropriate format so that it can used in jbuild
|
||||
files with "(:include [fname])". *)
|
||||
module Flags : sig
|
||||
|
||||
val write_sexp : string -> string list -> unit
|
||||
(** [write_sexp fname s] writes the list of strings [s] to the file [fname] in
|
||||
an appropriate format so that it can used in jbuild files with [(:include
|
||||
[fname])]. *)
|
||||
|
||||
val write_lines : string -> string list -> unit
|
||||
(** [write_lines fname s] writes the list of string [s] to the file [fname]
|
||||
with one line per string so that it can be used in Dune action rules with
|
||||
[%{read-lines:<path>}]. *)
|
||||
|
||||
val extract_comma_space_separated_words : string -> string list
|
||||
(** [extract_comma_space_separated_words s] returns a list of words in
|
||||
[s] that are separated by a newline, tab, space or comma character. *)
|
||||
|
||||
val extract_blank_separated_words : string -> string list
|
||||
(** [extract_blank_separated_words s] returns a list of words in [s]
|
||||
that are separated by a tab or space character. *)
|
||||
|
||||
val extract_words : string -> is_word_char:(char -> bool) -> string list
|
||||
(** [extract_words s ~is_word_char] will split the string [s] into
|
||||
a list of words. A valid word character is defined by the [is_word_char]
|
||||
predicate returning true and anything else is considered a separator.
|
||||
Any blank words are filtered out of the results. *)
|
||||
end
|
||||
|
||||
(** Typical entry point for configurator programs *)
|
||||
val main
|
||||
|
|
15
src/pform.ml
15
src/pform.ml
|
@ -30,6 +30,7 @@ module Macro = struct
|
|||
| Read_strings
|
||||
| Read_lines
|
||||
| Path_no_dep
|
||||
| Ocaml_config
|
||||
end
|
||||
|
||||
type 'a t =
|
||||
|
@ -77,6 +78,7 @@ module Map = struct
|
|||
; "findlib", renamed_in ~version:(1, 0) ~new_name:"lib"
|
||||
|
||||
; "path-no-dep", deleted_in ~version:(1, 0) Path_no_dep
|
||||
; "ocaml-config", macro Ocaml_config
|
||||
]
|
||||
|> String.Map.of_list_exn
|
||||
|
||||
|
@ -126,18 +128,7 @@ module Map = struct
|
|||
; "profile" , string context.profile
|
||||
]
|
||||
in
|
||||
let ocaml_config =
|
||||
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
|
||||
[ ocaml_config
|
||||
; static_vars
|
||||
[ static_vars
|
||||
; lowercased
|
||||
; uppercased
|
||||
; vars
|
||||
|
|
|
@ -22,6 +22,7 @@ module Macro : sig
|
|||
| Read_strings
|
||||
| Read_lines
|
||||
| Path_no_dep
|
||||
| Ocaml_config
|
||||
end
|
||||
|
||||
type 'a t =
|
||||
|
|
|
@ -47,6 +47,7 @@ type t =
|
|||
; cxx_flags : string list
|
||||
; vars : Pform.Var.t Pform.Map.t
|
||||
; macros : Pform.Macro.t Pform.Map.t
|
||||
; ocaml_config : Value.t list String.Map.t
|
||||
; chdir : (Action.t, Action.t) Build.t
|
||||
; host : t option
|
||||
; libs_by_package : (Package.t * Lib.Set.t) Package.Name.Map.t
|
||||
|
@ -99,20 +100,36 @@ let expand_macro t ~syntax_version ~var =
|
|||
Exn.code_error "expand_macro can't expand variables"
|
||||
[ "var", String_with_vars.Var.sexp_of_t var ]
|
||||
|
||||
let expand t ~syntax_version ~var =
|
||||
match
|
||||
match String_with_vars.Var.destruct var with
|
||||
| Var _ -> Left (expand_vars t ~syntax_version ~var)
|
||||
| Macro (_, _) -> Right (expand_macro t ~syntax_version ~var)
|
||||
with
|
||||
| Right None
|
||||
| Left None -> None
|
||||
| Right (Some x) -> Some (Right x)
|
||||
| Left (Some x) -> Some (Left x)
|
||||
|
||||
let (expand_vars_string, expand_vars_path) =
|
||||
let expand t ~scope ~dir ?(extra_vars=String.Map.empty) s =
|
||||
String_with_vars.expand ~mode:Single ~dir s ~f:(fun var syntax_version ->
|
||||
match expand_vars t ~syntax_version ~var with
|
||||
match expand t ~syntax_version ~var with
|
||||
| None ->
|
||||
String.Map.find extra_vars (String_with_vars.Var.full_name var)
|
||||
| Some v ->
|
||||
| Some (Left v) ->
|
||||
begin match Pform.Var.to_value_no_deps_or_targets ~scope v with
|
||||
| Some _ as v -> v
|
||||
| None ->
|
||||
Loc.fail (String_with_vars.Var.loc var)
|
||||
"Variable %a is not allowed in this context"
|
||||
String_with_vars.Var.pp var
|
||||
end)
|
||||
end
|
||||
| Some (Right Ocaml_config) ->
|
||||
String.Map.find t.ocaml_config (String_with_vars.Var.name var)
|
||||
| Some (Right _) ->
|
||||
Loc.fail (String_with_vars.Var.loc var)
|
||||
"This percent form isn't allowed in this position")
|
||||
in
|
||||
let expand_vars t ~scope ~dir ?extra_vars s =
|
||||
expand t ~scope ~dir ?extra_vars s
|
||||
|
@ -290,6 +307,19 @@ let create
|
|||
~f:(fun s -> not (String.is_prefix s ~prefix:"-std="))
|
||||
in
|
||||
let vars = Pform.Map.create_vars ~context ~cxx_flags in
|
||||
let ocaml_config =
|
||||
let string s = [Value.String s] in
|
||||
Ocaml_config.to_list context.ocaml_config
|
||||
|> List.map ~f:(fun (k, v) ->
|
||||
( 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 -> Value.L.strings x
|
||||
| Prog_and_args x -> Value.L.strings (x.prog :: x.args)))
|
||||
|> String.Map.of_list_exn
|
||||
in
|
||||
let t =
|
||||
{ context
|
||||
; host
|
||||
|
@ -305,6 +335,7 @@ let create
|
|||
; cxx_flags
|
||||
; vars
|
||||
; macros = Pform.Map.macros
|
||||
; ocaml_config
|
||||
; chdir = Build.arr (fun (action : Action.t) ->
|
||||
match action with
|
||||
| Chdir _ -> action
|
||||
|
@ -597,6 +628,7 @@ module Action = struct
|
|||
let key = String_with_vars.Var.full_name var in
|
||||
begin match expand_macro sctx ~syntax_version ~var with
|
||||
| Some Pform.Macro.Exe -> Some (path_exp (map_exe (Path.relative dir s)))
|
||||
| Some Ocaml_config -> String.Map.find sctx.ocaml_config s
|
||||
| Some Dep -> Some (path_exp (Path.relative dir s))
|
||||
| Some Bin -> begin
|
||||
let sctx = host sctx in
|
||||
|
|
|
@ -436,6 +436,14 @@
|
|||
test-cases/null-dep
|
||||
(progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected)))))
|
||||
|
||||
(alias
|
||||
(name ocaml-config-macro)
|
||||
(deps (package dune) (source_tree test-cases/ocaml-config-macro))
|
||||
(action
|
||||
(chdir
|
||||
test-cases/ocaml-config-macro
|
||||
(progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected)))))
|
||||
|
||||
(alias
|
||||
(name ocaml-syntax)
|
||||
(deps (package dune) (source_tree test-cases/ocaml-syntax))
|
||||
|
@ -698,6 +706,7 @@
|
|||
(alias multiple-private-libs)
|
||||
(alias no-installable-mode)
|
||||
(alias null-dep)
|
||||
(alias ocaml-config-macro)
|
||||
(alias ocaml-syntax)
|
||||
(alias ocamldep-multi-stanzas)
|
||||
(alias odoc)
|
||||
|
@ -773,6 +782,7 @@
|
|||
(alias misc)
|
||||
(alias no-installable-mode)
|
||||
(alias null-dep)
|
||||
(alias ocaml-config-macro)
|
||||
(alias ocaml-syntax)
|
||||
(alias ocamldep-multi-stanzas)
|
||||
(alias output-obj)
|
||||
|
|
|
@ -4,5 +4,5 @@ inappropariate place:
|
|||
$ dune build
|
||||
Info: creating file dune-project with this contents: (lang dune 1.0)
|
||||
File "dune", line 1, characters 14-21:
|
||||
Error: macros of the form %{name:..} cannot be expanded here
|
||||
Error: This percent form isn't allowed in this position
|
||||
[1]
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
(rule
|
||||
(targets x)
|
||||
(action (with-stdout-to %{targets} (echo %{ocaml-config:system}))))
|
|
@ -0,0 +1 @@
|
|||
(lang dune 1.0)
|
|
@ -0,0 +1,4 @@
|
|||
%{ocaml-config:...} macros should be available. we don't print anything because
|
||||
the values are all platform specific.
|
||||
|
||||
$ dune build
|
|
@ -21,19 +21,19 @@
|
|||
(rule
|
||||
(targets static.exe)
|
||||
(deps test.exe%{ext_obj} static.c)
|
||||
(action (run %{CC} -o %{targets} -I %{ocaml_where} -I . %{deps}
|
||||
(action (run %{cc} -o %{targets} -I %{ocaml_where} -I . %{deps}
|
||||
%{ocaml-config:native_c_libraries})))
|
||||
|
||||
(rule
|
||||
(targets static.bc)
|
||||
(deps test.bc%{ext_obj} static.c)
|
||||
(action (run %{CC} -o %{targets} -I %{ocaml_where} -I . %{deps}
|
||||
(action (run %{cc} -o %{targets} -I %{ocaml_where} -I . %{deps}
|
||||
%{ocaml-config:bytecomp_c_libraries})))
|
||||
|
||||
(rule
|
||||
(targets dynamic.exe)
|
||||
(deps dynamic.c)
|
||||
(action (run %{CC} -o %{targets} %{first-dep} %{ocaml-config:native_c_libraries})))
|
||||
(action (run %{cc} -o %{targets} %{first-dep} %{ocaml-config:native_c_libraries})))
|
||||
|
||||
(alias
|
||||
(name runtest)
|
||||
|
|
Loading…
Reference in New Issue