-
Notifications
You must be signed in to change notification settings - Fork 412
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
Conversation
The `write_flags` only works with `(:include` directives, and it is also useful to be able to write a list of lines so that the discovered information can be used in variable expansion actions. For example, ocaml-yaml discovers CFLAGS and then directly has `(run ${CC} ${read-lines:cflags})` actions that use this new write_lines function to list cflags instead of s-expressions. They must be line-by-line or else variable expansion doesnt work since CFLAGS contain spaces. Signed-off-by: Anil Madhavapeddy <anil@recoil.org>
I used something like that in one of my packages as well. |
src/configurator/v1.ml
Outdated
let write_lines fname s = | ||
let path = Path.of_string fname in | ||
let buf = String.concat ~sep:"\n" s in | ||
Io.write_file path buf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Io.write_lines
please.
BTW, it's not urgent but one day we should deprecate |
Agreed. We should deprecate |
Won't |
Hm, I ran into a quoting issue when using this, so this might be worth revising a little. A cflags file contains (e.g.):
This then needs to be passed as individual atoms to the build action, which only happens (I think) when we actually write it as follows:
...and use the As a result, ocaml-yaml now uses this fragment to generate the file:
Should we adapt a similar function to split newlines into individual lines, or is there some other way to unquote strings with spaces? |
We have the three following functions in Stdune.String: val extract_words : t -> is_word_char:(char -> bool) -> t list
val extract_comma_space_separated_words : t -> t list
val extract_blank_separated_words : t -> t list We could expose and document them in |
Does the interface I've pushed make sense? I moved the Flags handling into its own module and made the write_flags explicitly mention |
Looks good. Though if the plan is to get rid of @diml are we convinced that |
I'm convinced it has to go |
I think so too if that matters. |
The final verdict was that @avsm would you mind rebasing this PR? It looks ready. |
|
||
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Thanks @diml. I will resolve the conflicts and merge this PR manually |
The
write_flags
only works with(:include
directives, and itis also useful to be able to write a list of lines so that the
discovered information can be used in variable expansion actions.
For example, ocaml-yaml discovers CFLAGS and then directly has
(run ${CC} ${read-lines:cflags})
actions that use this newwrite_lines function to list cflags instead of s-expressions.
They must be line-by-line or else variable expansion doesnt work
since CFLAGS contain spaces.
Signed-off-by: Anil Madhavapeddy anil@recoil.org