diff --git a/src/configurator/v1.ml b/src/configurator/v1.ml index 0f38eee2815..5d0f6875941 100644 --- a/src/configurator/v1.ml +++ b/src/configurator/v1.ml @@ -61,6 +61,21 @@ 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_include_flags fname s = + let path = Path.of_string fname in + let sexp = Usexp.List(List.map ~f:Usexp.atom_or_quoted_string s) in + Io.write_file path (Usexp.to_string sexp) + + let write_lines fname s = + let path = Path.of_string fname in + Io.write_lines path s +end + module Find_in_path = struct let path_sep = if Sys.win32 then @@ -478,18 +493,13 @@ module Pkg_config = struct None end -let write_flags fname s = - let path = Path.of_string fname in - let sexp = Usexp.List(List.map ~f:Usexp.atom_or_quoted_string s) in - Io.write_file path (Usexp.to_string sexp) - 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 diff --git a/src/configurator/v1.mli b/src/configurator/v1.mli index 5eb9ebb7125..0e68a3ea06d 100644 --- a/src/configurator/v1.mli +++ b/src/configurator/v1.mli @@ -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_include_flags : string -> string list -> unit + (** [write_flags 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:}]. *) + + 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