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

Let "concat" or "split" be a quality of the variable #336

Merged
10 commits merged into from
Jan 15, 2018

Conversation

Chris00
Copy link
Member

@Chris00 Chris00 commented Nov 23, 2017

No description provided.

@Chris00
Copy link
Member Author

Chris00 commented Nov 23, 2017

One could imagine that split variables say what is their separator so, say, ${ocaml_version} could be by default split as 3 components and "${ocaml_version}" would concat them on "." — but this is maybe going too far (it is not part of this PR)!

@rgrinberg
Copy link
Member

From a first glance, the implementation here looks good. Though I'm not yet sure why is this feature necessary and where it can be useful.

A couple of minor nits:

  • Use ocp-indent to format your source. There are some indentation issues here
  • The jbuilder source uses 90 columns for wrapping rather than 80. I have no idea and it's not my preference but it's best to maintain this. Or at least not introduce spurious changes to this.

@Chris00
Copy link
Member Author

Chris00 commented Nov 26, 2017

I'm not yet sure why is this feature necessary and where it can be useful.

This is an alternative solution to #300
Wit this (run ${CC} ...) will behave as expected without the need for !.

@Chris00
Copy link
Member Author

Chris00 commented Nov 26, 2017

Use ocp-indent to format your source.

I did but it changed lines I did not modify. I made it a separate commit so it is easily revertible.

@Chris00
Copy link
Member Author

Chris00 commented Nov 26, 2017

not introduce spurious changes to this.

I reverted the single line affected by this (and merged it with the original commit).

@Chris00
Copy link
Member Author

Chris00 commented Nov 26, 2017

I'm not yet sure why is this feature necessary and where it can be useful.

Actually, the logical sequel to this change is to put a warning when using ! and adapting the manual.

@ghost
Copy link

ghost commented Dec 20, 2017

I had a look at this PR. I just like to say that I'm a bit ashamed of the !... it is a bit nasty indeed and only exists for historical reasons. This PR goes in the right direction, whether a variable is a string or a list is indeed a property of the variable.

One reason I didn't do this earlier is that I'm a bit nervous about this:

let cflags = String.extract_blank_separated_words context.ocamlc_cflags in

ocamlc_cflags comes from the output of ocamlc -config, and all we know about it is that it is a string that can be passed unquoted to Sys.command. In particular, splitting it might not be enough, we might need to unquote as well and interpret quotes and double quotes. And of course, this parsing is dependent on the OS...

In the end, I would still like to see this PR merged. It's unlikely that such ocamlc_cflags will contain complicated stuff, and we could always fallback to ["/bin/sh"; "-c"; "<cc>"; "<cflags>"] when it's too complicated to parse.

So before we merge it, I'd like to know two things:

  • that someone is happy to deal with such quoting problems when they arise
  • what is the impact on existing packages

The only case of breakage I can think of is the following:

(run foo.exe -cc ${CC})

The fix is easy: just write "${CC} ". But we should make sure that this is done before we merge this. We can look at the jbuilder-universe to find packages that are affected. If no packages are affected, I'm ok doing the change at once. If several packages are affected, we should do a first relaese that prints a warning on such cases, fix all packages and then merge this.

@Chris00
Copy link
Member Author

Chris00 commented Dec 20, 2017

A quick grep on the jbuilder-universe shows that very few packages use ${CC}:

None of these uses is problematic with the new behavior.

@Chris00
Copy link
Member Author

Chris00 commented Dec 20, 2017

that someone is happy to deal with such quoting problems when they arise

I can provided nobody is in a hurry — I may not be able to react within a week. I may also need help to test the Windows side (I so not have a readily available Windows machine).

let make =
match Bin.make with
| None -> "make"
| Some p -> Path.to_string p
| None -> Paths ([Path.of_string "make"], Split)
Copy link

Choose a reason for hiding this comment

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

This needs to be Strings, otherwise jbuilder is going to think it's the file "make" in the current dir and expand it to ./make

@ghost
Copy link

ghost commented Dec 21, 2017

Ok, thanks. After the discussion on slack I'm less worried about this anyway.

Could you update the doc as well?

@Chris00 Chris00 force-pushed the split_var branch 3 times, most recently from c65f1a2 to d6bd318 Compare December 25, 2017 12:19
@Chris00
Copy link
Member Author

Chris00 commented Dec 25, 2017

I updated the code following your remarks — and more :-)

Chris00 added a commit to Chris00/mesh that referenced this pull request Jan 4, 2018
This requires ${CC} to be a split variable, see
ocaml/dune#336
doc/jbuild.rst Outdated

.. code:: scheme

(run foo "${^}")
Copy link

Choose a reason for hiding this comment

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

This is not true at the moment. The double quotes are only seen by the lexer. From the point of view of jbuilder, hello and "hello" are exactly the same atom.

We could change jbuilder to keep this information and do different things according to whether atoms are quoted or not. This might make sense given that the syntax is different from the user point of view. However, we should have this discussion in a different ticket to avoid delaying this PR.

For now, the user has to add a space at the beginning or end of the atom:

(run foo "${^} ")

Copy link
Member Author

Choose a reason for hiding this comment

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

Opened #408

let has_bang, var = parse_bang key in
if has_bang then
Format.eprintf "@{<warning>Warning@}: The use of the variable \
prefix '!' is deprecated, simply use '${%s}'@." var;
Copy link

Choose a reason for hiding this comment

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

Can you use Loc.warn loc "The use ..."?

(* CR-someday jdimino: this should be an error *)
Strings ([""], cos)
Format.eprintf "@{<warning>Warning@}: Variable '<' used with \
no explicit dependencies@.";
Copy link

Choose a reason for hiding this comment

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

Same remark about Loc.warn

@ghost
Copy link

ghost commented Jan 9, 2018

Thanks, I left some minor comment but otherwise it looks ready

@Chris00
Copy link
Member Author

Chris00 commented Jan 12, 2018

Also fixed the conflicts.

@ghost ghost merged commit f8617b5 into ocaml:master Jan 15, 2018
@ghost
Copy link

ghost commented Jan 15, 2018

Thanks

@Chris00 Chris00 deleted the split_var branch January 15, 2018 10:20
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants