From 11c61b32346de2cd4fdfafab7926bde3feebfd69 Mon Sep 17 00:00:00 2001 From: Jeremie Dimino Date: Fri, 23 Dec 2016 15:32:23 +0000 Subject: [PATCH] 114.20+69 --- src/gen_rules.ml | 4 +-- src/jbuild_types.ml | 10 +++--- src/ordered_set_lang.ml | 4 +-- src/ordered_set_lang.mli | 4 +-- src/string_with_vars.ml | 72 ++++++++++++++++++++++++---------------- src/string_with_vars.mli | 5 ++- 6 files changed, 59 insertions(+), 40 deletions(-) diff --git a/src/gen_rules.ml b/src/gen_rules.ml index a0273c68..a28130fc 100644 --- a/src/gen_rules.ml +++ b/src/gen_rules.ml @@ -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 diff --git a/src/jbuild_types.ml b/src/jbuild_types.ml index 5b35450a..04c2b431 100644 --- a/src/jbuild_types.ml +++ b/src/jbuild_types.ml @@ -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 diff --git a/src/ordered_set_lang.ml b/src/ordered_set_lang.ml index c0ef4fff..7db68269 100644 --- a/src/ordered_set_lang.ml +++ b/src/ordered_set_lang.ml @@ -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 _ -> "") | List l -> List (List.map l ~f:(expand ~files_contents)) diff --git a/src/ordered_set_lang.mli b/src/ordered_set_lang.mli index 1729bb3d..8c8c67dd 100644 --- a/src/ordered_set_lang.mli +++ b/src/ordered_set_lang.mli @@ -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 diff --git a/src/string_with_vars.ml b/src/string_with_vars.ml index 056dfa6f..83ed397a 100644 --- a/src/string_with_vars.ml +++ b/src/string_with_vars.ml @@ -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) diff --git a/src/string_with_vars.mli b/src/string_with_vars.mli index c4009626..9de3556e 100644 --- a/src/string_with_vars.mli +++ b/src/string_with_vars.mli @@ -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