Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] configurator: add write_lines function #840

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions src/configurator/v1.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last thing: can you replace atom_or_quoted_string by (fun x -> Quoted_string x)? This will ensure that the produced files are compatible with both the jbuild and dune lexical conventions.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this in #967

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
Expand Down Expand Up @@ -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
Expand Down
30 changes: 26 additions & 4 deletions src/configurator/v1.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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:<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
Expand Down