-
Notifications
You must be signed in to change notification settings - Fork 413
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
Allow to split all variables & proper error when using them in strings #309
Conversation
I haven't looked closely, but what happens, for example, if |
@dra27 Yes, I forgot to mention that I'm not convinced that |
@Chris00 do you have a CLA submitted to JST? You might want to get that done while we're reviewing this PR. |
On 2017-11-07, Rudi Grinberg wrote:
@Chris00 do you have a CLA submitted to JST? You might want to get that done while we're reviewing this PR.
I don’t. Where do I find it?
|
If you have a windows box ready, then it's just
I don't think so |
@rgrinberg I do not have a Windows box, that's why I was asking (I could run AppVeyor but I do not have the time to write the script right now). |
It doesn't include by default include a hard-coded directory. Here's a 4.06 msvc64 example: This should work - I'm just wondering whether we should use this opportunity to do some better for specifying compound "commands" like this. I'm for example having to use hacks to get jbuilder to run the compiler when it's a bytecode image with no header (so has to be invoked via ocamlrun). It's tempting to allow this now, but if we then improve the handling later we'd probably want to remove this behaviour again? |
@dra27 Could you precise what you have in mind? I wonder if variables are considered as lists ( |
What concerns me slightly is that the present I'm wondering if jbuilder should be doing something (potentially hideous) along the lines of how CreateProcess works - so ${CC} should just be automatically split when used in the "head" context of a This isn't entirely hypothetical - I know for example that LexiFi use absolute paths to C compilers in order to differentiate 32 and 64-bit Microsoft C compilers, so while I think what you're suggesting here works now, I can see a problem lurking shortly round the corner... |
I also have a small fear that we're heading towards |
I think it should be the other way around: |
Yes, but what therefore does "split" mean - because just splitting it on spaces is not semantically correct when the first "component" should itself include some spaces. The shell's not the greatest inspiration for this, as it tends to be a nightmare there too! |
The variable |
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.
Sorry for taking a while to review this properly. Minor changes - it basically looks good to me. My previous concern about splitting program names with spaces incorrectly was, as you politely pointed out, erroneous as it'll only be as bad as the output of ocamlc -config
(i.e. it's good in 4.06.0+ where the compiler and flags are separate items and potentially bad in older versions)
src/action.ml
Outdated
@@ -200,7 +200,8 @@ module Var_expansion = struct | |||
| Paths (l, Concat) -> [concat (List.map l ~f:(string_of_path ~dir))] | |||
|
|||
let to_string ~dir = function | |||
| Strings (_, Split) | Paths (_, Split) -> assert false | |||
| Strings (_, Split) | Paths (_, Split) -> | |||
failwith "Action.Var_expansion.to_string" |
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.
Given that this wants to be matched on later, I think it would be better to define an exception, rather than use Failure
src/action.ml
Outdated
try Some (VE.to_string ~dir e) | ||
with Failure _ -> | ||
let msg = sprintf "Split variable %S in string does not \ | ||
make sense" var 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.
Given the message, I'd match an explicit exception just to guard against some future additional failure mode.
I know there's another message which refers to things not making sense, but I think something more descriptive of what doesn't make sense would be better, e.g. "${!%S} is a list and so cannot be used in a string (did you mean just ${%S}"
It's also tempting just to say that "${!@}" = "${@}"
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.
It's also tempting just to say that "${!@}" = "${@}"
Indeed! (My take on this is that splitable variables should come be default as such — so that, say, (run ${CC}
always does what is expected — and are concatenated with spaces if used in a string — e.g. (run "${CC}"
to have the old behavior) .
src/super_context.ml
Outdated
let expand_var_no_root t var = String_map.find var t.vars | ||
let expand_var_no_root t var cos = | ||
match String_map.find var t.vars with | ||
| Some v -> Some(v cos) |
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.
Nit: space before the (
src/super_context.ml
Outdated
let p = List.map p ~f:Path.to_string in | ||
Some (String.concat ~sep:" " p) | ||
| Some(Strings(s,_)) -> Some (String.concat ~sep:" " s) | ||
| None -> None) |
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.
Please could this be refactored as a function and a call to Option.map
?
src/super_context.ml
Outdated
[ "-verbose" , str_exp [] (*"-verbose";*) | ||
; "CPP" , str_exp (context.c_compiler :: cflags @ ["-E"]) | ||
; "PA_CPP" , str_exp (context.c_compiler :: cflags | ||
@ ["-undef -traditional"; "-x"; "c"; "-E"]) |
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.
Shouldn't "-undef -traditional"
be "-undef"; "-traditional"
?
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.
Yes.
I'll try to make the requested changes tomorrow. |
Thank you - I shall endeavour not to take so long to review them this time! |
Before this change, using, say ${!@}, in a string was making an assertion fail.
To show what I meant by "splitable variables should come be default as such", see #336 |
I suppose that #336 replaced this PR |
Fix issue #300