114.20+69
This commit is contained in:
parent
ea888074b0
commit
11c61b3234
|
@ -782,7 +782,7 @@ module Gen(P : Params) = struct
|
|||
~modules
|
||||
~mode
|
||||
(String_map.keys modules)))
|
||||
(expand_and_eval_set ~dir lib.cclibs ~standard:[])
|
||||
(expand_and_eval_set ~dir lib.c_libraries ~standard:[])
|
||||
>>>
|
||||
Build.run (Dep compiler)
|
||||
~extra_targets:(
|
||||
|
@ -974,7 +974,7 @@ module Gen(P : Params) = struct
|
|||
| None ->
|
||||
let targets = [ stubs_archive lib ~dir; dll lib ~dir ] in
|
||||
add_rule
|
||||
(expand_and_eval_set ~dir lib.cclibs ~standard:[]
|
||||
(expand_and_eval_set ~dir lib.c_libraries ~standard:[]
|
||||
>>>
|
||||
Build.run
|
||||
~extra_targets:targets
|
||||
|
|
|
@ -329,7 +329,7 @@ module Library = struct
|
|||
; cxx_names : string list
|
||||
; includes : String_with_vars.t list
|
||||
; library_flags : String_with_vars.t list
|
||||
; cclibs : Ordered_set_lang.Unexpanded.t
|
||||
; c_libraries : Ordered_set_lang.Unexpanded.t
|
||||
; preprocess : Preprocess_map.t
|
||||
; preprocessor_deps : Dep_conf.t list
|
||||
; self_build_stubs_archive : string option
|
||||
|
@ -358,7 +358,7 @@ module Library = struct
|
|||
; field "c_names" (list string) ~default:[]
|
||||
; field "cxx_names" (list string) ~default:[]
|
||||
; field "library_flags" (list String_with_vars.t) ~default:[]
|
||||
; field_oslu "cclibs"
|
||||
; field_oslu "c_libraries"
|
||||
; field_pp "preprocess"
|
||||
; field "preprocessor_deps" (list Dep_conf.t) ~default:[]
|
||||
; field "self_build_stubs_archive" (option string) ~default:None
|
||||
|
@ -374,7 +374,7 @@ module Library = struct
|
|||
; field_osl "ocamlopt_flags"
|
||||
]
|
||||
(fun name public_name synopsis public_headers libraries ppx_runtime_libraries
|
||||
modules c_flags cxx_flags c_names cxx_names library_flags cclibs preprocess
|
||||
modules c_flags cxx_flags c_names cxx_names library_flags c_libraries preprocess
|
||||
preprocessor_deps self_build_stubs_archive js_of_ocaml virtual_deps modes
|
||||
includes kind wrapped optional flags ocamlc_flags ocamlopt_flags ->
|
||||
{ name
|
||||
|
@ -392,7 +392,7 @@ module Library = struct
|
|||
; cxx_flags
|
||||
; includes
|
||||
; library_flags
|
||||
; cclibs
|
||||
; c_libraries
|
||||
; preprocess
|
||||
; preprocessor_deps
|
||||
; self_build_stubs_archive
|
||||
|
@ -465,7 +465,7 @@ module Rule = struct
|
|||
}
|
||||
|
||||
let t =
|
||||
record
|
||||
record ~ignore:["sandbox"]
|
||||
[ field "targets" (list file_in_current_dir)
|
||||
; field "deps" (list Dep_conf.t)
|
||||
; field "action" User_action.Unexpanded.t
|
||||
|
|
|
@ -63,7 +63,7 @@ module Unexpanded = struct
|
|||
let files t =
|
||||
let rec loop acc : t -> _ = function
|
||||
| Atom _ -> acc
|
||||
| List [Atom "<"; Atom fn] -> String_set.add fn acc
|
||||
| List [Atom ":include"; Atom fn] -> String_set.add fn acc
|
||||
| List l -> List.fold_left l ~init:acc ~f:loop
|
||||
in
|
||||
loop String_set.empty t
|
||||
|
@ -71,7 +71,7 @@ module Unexpanded = struct
|
|||
let rec expand (t : t) ~files_contents =
|
||||
match t with
|
||||
| Atom _ -> t
|
||||
| List [Atom "<"; Atom fn] ->
|
||||
| List [Atom ":include"; Atom fn] ->
|
||||
String_map.find_exn fn files_contents ~string_of_key:(sprintf "%S")
|
||||
~desc:(fun _ -> "<filename to s-expression>")
|
||||
| List l -> List (List.map l ~f:(expand ~files_contents))
|
||||
|
|
|
@ -23,7 +23,7 @@ module Unexpanded : sig
|
|||
val files : t -> String_set.t
|
||||
|
||||
(** Expand [t] using with the given file contents. [file_contents] is a map from
|
||||
filenames to their parsed contents. Every [(< fn)] in [t] is replaced by [Map.find
|
||||
files_contents fn]. *)
|
||||
filenames to their parsed contents. Every [(:include fn)] in [t] is replaced by
|
||||
[Map.find files_contents fn]. *)
|
||||
val expand : t -> files_contents:Sexp.t String_map.t -> expanded
|
||||
end with type expanded := t
|
||||
|
|
|
@ -8,36 +8,52 @@ type item =
|
|||
|
||||
type t = item list
|
||||
|
||||
let syntax_of_opening = function
|
||||
| '{' -> Braces
|
||||
| '(' -> Parens
|
||||
| _ -> assert false
|
||||
module Token = struct
|
||||
type t =
|
||||
| String of string
|
||||
| Open of var_syntax
|
||||
| Close of var_syntax
|
||||
|
||||
let of_string s =
|
||||
let len = String.length s in
|
||||
let sub i j = String.sub s ~pos:i ~len:(j - i) in
|
||||
let cons_text i j acc = if i = j then acc else Text (sub i j) :: acc in
|
||||
let rec loop i j =
|
||||
if j = len then
|
||||
cons_text i j []
|
||||
else
|
||||
match s.[j] with
|
||||
| '$' -> begin
|
||||
match
|
||||
let tokenise s =
|
||||
let len = String.length s in
|
||||
let sub i j = String.sub s ~pos:i ~len:(j - i) in
|
||||
let cons_str i j acc = if i = j then acc else String (sub i j) :: acc in
|
||||
let rec loop i j =
|
||||
if j = len
|
||||
then cons_str i j []
|
||||
else
|
||||
match s.[j] with
|
||||
| '}' -> cons_str i j (Close Braces :: loop (j + 1) (j + 1))
|
||||
| ')' -> cons_str i j (Close Parens :: loop (j + 1) (j + 1))
|
||||
| '$' -> begin
|
||||
match s.[j + 1] with
|
||||
| '{' -> String.index_from s (j + 2) '}'
|
||||
| '(' -> String.index_from s (j + 2) ')'
|
||||
| _ -> raise Not_found
|
||||
with
|
||||
| exception Not_found -> loop i (j + 1)
|
||||
| var_end ->
|
||||
let var = sub (j + 2) var_end in
|
||||
let syntax = syntax_of_opening s.[j + 1] in
|
||||
cons_text i j (Var (syntax, var) :: loop (var_end + 1) (var_end + 1))
|
||||
end
|
||||
| _ -> loop i (j + 1)
|
||||
in
|
||||
loop 0 0
|
||||
| '{' -> cons_str i j (Open Braces :: loop (j + 2) (j + 2))
|
||||
| '(' -> cons_str i j (Open Parens :: loop (j + 2) (j + 2))
|
||||
| _ -> loop i (j + 1)
|
||||
end
|
||||
| _ -> loop i (j + 1)
|
||||
in
|
||||
loop 0 0
|
||||
|
||||
let to_string = function
|
||||
| String s -> s
|
||||
| Open Braces -> "${"
|
||||
| Open Parens -> "$("
|
||||
| Close Braces -> "}"
|
||||
| Close Parens -> ")"
|
||||
end
|
||||
|
||||
let rec of_tokens : Token.t list -> t = function
|
||||
| [] -> []
|
||||
| Open a :: String s :: Close b :: rest when a = b ->
|
||||
Var (a, s) :: of_tokens rest
|
||||
| token :: rest ->
|
||||
let s = Token.to_string token in
|
||||
match of_tokens rest with
|
||||
| Text s' :: l -> Text (s ^ s') :: l
|
||||
| l -> Text s :: l
|
||||
|
||||
let of_string s = of_tokens (Token.tokenise s)
|
||||
|
||||
let t sexp = of_string (Sexp.Of_sexp.string sexp)
|
||||
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
(** String with variables of the form ${...} or $(...) *)
|
||||
(** String with variables of the form ${...} or $(...)
|
||||
|
||||
Variables cannot contain "${", "$(", ")" or "}". For instance in "$(cat ${x})", only
|
||||
"${x}" will be considered a variable, the rest is text. *)
|
||||
|
||||
open Import
|
||||
|
||||
|
|
Loading…
Reference in New Issue