114.20+69

This commit is contained in:
Jeremie Dimino 2016-12-23 15:32:23 +00:00
parent ea888074b0
commit 11c61b3234
6 changed files with 59 additions and 40 deletions

View File

@ -782,7 +782,7 @@ module Gen(P : Params) = struct
~modules ~modules
~mode ~mode
(String_map.keys modules))) (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) Build.run (Dep compiler)
~extra_targets:( ~extra_targets:(
@ -974,7 +974,7 @@ module Gen(P : Params) = struct
| None -> | None ->
let targets = [ stubs_archive lib ~dir; dll lib ~dir ] in let targets = [ stubs_archive lib ~dir; dll lib ~dir ] in
add_rule add_rule
(expand_and_eval_set ~dir lib.cclibs ~standard:[] (expand_and_eval_set ~dir lib.c_libraries ~standard:[]
>>> >>>
Build.run Build.run
~extra_targets:targets ~extra_targets:targets

View File

@ -329,7 +329,7 @@ module Library = struct
; cxx_names : string list ; cxx_names : string list
; includes : String_with_vars.t list ; includes : String_with_vars.t list
; library_flags : 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 ; preprocess : Preprocess_map.t
; preprocessor_deps : Dep_conf.t list ; preprocessor_deps : Dep_conf.t list
; self_build_stubs_archive : string option ; self_build_stubs_archive : string option
@ -358,7 +358,7 @@ module Library = struct
; field "c_names" (list string) ~default:[] ; field "c_names" (list string) ~default:[]
; field "cxx_names" (list string) ~default:[] ; field "cxx_names" (list string) ~default:[]
; field "library_flags" (list String_with_vars.t) ~default:[] ; field "library_flags" (list String_with_vars.t) ~default:[]
; field_oslu "cclibs" ; field_oslu "c_libraries"
; field_pp "preprocess" ; field_pp "preprocess"
; field "preprocessor_deps" (list Dep_conf.t) ~default:[] ; field "preprocessor_deps" (list Dep_conf.t) ~default:[]
; field "self_build_stubs_archive" (option string) ~default:None ; field "self_build_stubs_archive" (option string) ~default:None
@ -374,7 +374,7 @@ module Library = struct
; field_osl "ocamlopt_flags" ; field_osl "ocamlopt_flags"
] ]
(fun name public_name synopsis public_headers libraries ppx_runtime_libraries (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 preprocessor_deps self_build_stubs_archive js_of_ocaml virtual_deps modes
includes kind wrapped optional flags ocamlc_flags ocamlopt_flags -> includes kind wrapped optional flags ocamlc_flags ocamlopt_flags ->
{ name { name
@ -392,7 +392,7 @@ module Library = struct
; cxx_flags ; cxx_flags
; includes ; includes
; library_flags ; library_flags
; cclibs ; c_libraries
; preprocess ; preprocess
; preprocessor_deps ; preprocessor_deps
; self_build_stubs_archive ; self_build_stubs_archive
@ -465,7 +465,7 @@ module Rule = struct
} }
let t = let t =
record record ~ignore:["sandbox"]
[ field "targets" (list file_in_current_dir) [ field "targets" (list file_in_current_dir)
; field "deps" (list Dep_conf.t) ; field "deps" (list Dep_conf.t)
; field "action" User_action.Unexpanded.t ; field "action" User_action.Unexpanded.t

View File

@ -63,7 +63,7 @@ module Unexpanded = struct
let files t = let files t =
let rec loop acc : t -> _ = function let rec loop acc : t -> _ = function
| Atom _ -> acc | 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 | List l -> List.fold_left l ~init:acc ~f:loop
in in
loop String_set.empty t loop String_set.empty t
@ -71,7 +71,7 @@ module Unexpanded = struct
let rec expand (t : t) ~files_contents = let rec expand (t : t) ~files_contents =
match t with match t with
| Atom _ -> t | Atom _ -> t
| List [Atom "<"; Atom fn] -> | List [Atom ":include"; Atom fn] ->
String_map.find_exn fn files_contents ~string_of_key:(sprintf "%S") String_map.find_exn fn files_contents ~string_of_key:(sprintf "%S")
~desc:(fun _ -> "<filename to s-expression>") ~desc:(fun _ -> "<filename to s-expression>")
| List l -> List (List.map l ~f:(expand ~files_contents)) | List l -> List (List.map l ~f:(expand ~files_contents))

View File

@ -23,7 +23,7 @@ module Unexpanded : sig
val files : t -> String_set.t val files : t -> String_set.t
(** Expand [t] using with the given file contents. [file_contents] is a map from (** 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 filenames to their parsed contents. Every [(:include fn)] in [t] is replaced by
files_contents fn]. *) [Map.find files_contents fn]. *)
val expand : t -> files_contents:Sexp.t String_map.t -> expanded val expand : t -> files_contents:Sexp.t String_map.t -> expanded
end with type expanded := t end with type expanded := t

View File

@ -8,36 +8,52 @@ type item =
type t = item list type t = item list
let syntax_of_opening = function module Token = struct
| '{' -> Braces type t =
| '(' -> Parens | String of string
| _ -> assert false | Open of var_syntax
| Close of var_syntax
let of_string s = let tokenise s =
let len = String.length s in let len = String.length s in
let sub i j = String.sub s ~pos:i ~len:(j - i) 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 cons_str i j acc = if i = j then acc else String (sub i j) :: acc in
let rec loop i j = let rec loop i j =
if j = len then if j = len
cons_text i j [] then cons_str i j []
else else
match s.[j] with match s.[j] with
| '$' -> begin | '}' -> cons_str i j (Close Braces :: loop (j + 1) (j + 1))
match | ')' -> cons_str i j (Close Parens :: loop (j + 1) (j + 1))
| '$' -> begin
match s.[j + 1] with match s.[j + 1] with
| '{' -> String.index_from s (j + 2) '}' | '{' -> cons_str i j (Open Braces :: loop (j + 2) (j + 2))
| '(' -> String.index_from s (j + 2) ')' | '(' -> cons_str i j (Open Parens :: loop (j + 2) (j + 2))
| _ -> raise Not_found | _ -> loop i (j + 1)
with end
| exception Not_found -> loop i (j + 1) | _ -> loop i (j + 1)
| var_end -> in
let var = sub (j + 2) var_end in loop 0 0
let syntax = syntax_of_opening s.[j + 1] in
cons_text i j (Var (syntax, var) :: loop (var_end + 1) (var_end + 1)) let to_string = function
end | String s -> s
| _ -> loop i (j + 1) | Open Braces -> "${"
in | Open Parens -> "$("
loop 0 0 | 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) let t sexp = of_string (Sexp.Of_sexp.string sexp)

View File

@ -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 open Import