ocamlc -config: new -config-var option to print specific configuration variables #1430

Merged
merged 1 commit into from Apr 30, 2018

Conversation

Projects
None yet
6 participants
Member

Member Author

gasche commented Nov 11, 2017

 I rebased, I believe all comments have been taken into account, and I added manpage and manual documentation.

Member

damiendoligez left a comment

 Looks pretty good but I have two remarks.
 @@ -38,7 +38,7 @@ endif OBJS=dynlinkaux.cmo dynlink.cmo COMPILEROBJS=\ ../../utils/misc.cmo ../../utils/config.cmo \ ../../utils/config.cmo ../../utils/misc.cmo \

damiendoligez Nov 13, 2017

Member

This makes me slightly nervous. Maybe show_config_and_exit and show_config_var_and_exit should be in config.ml rather than misc.ml?

gasche Nov 18, 2017

Author Member

I think that config should remain a "pure data" module as much as possible.

I don't think we should add logic to it. Maybe I could create a separate config_misc module depending on config?

On the other hand, I think that config should really be at the bottom of the module dependency graph (especially if we commit to keeping it a pure data module), so I think the change is right in the long term -- although I agree it makes us a bit nervous.

damiendoligez Jan 16, 2018

Member

I agree that Config should be a pure data module and that pure data modules should be at the bottom of the graph, so this is OK after all.

 let mk_config_var f = "-config-var", Arg.String f, " Print the value of a configuration variable, a newline, and exit \ (print nothing and exit with error value if the variable does not exist)"

damiendoligez Nov 13, 2017

Member

Could you please cut this message with \n\ and not make the compiler's help output look like shit (any more than it already does)?

gasche Nov 18, 2017

Author Member

@damiendoligez could I implement an Arg.wrap : ~line_length:int -> specs -> specs function instead of manually doing the job of choosing the right cut place depending on the option name and alignment choice?

Member

gasche Apr 10, 2018

Author Member

In the end I did the simple thing of adding turning the end-of-line \ into \n \.

Member Author

gasche commented Apr 10, 2018

 I had forgotten that this hadn't been merged yet (I thought of it because of #1691). I will do the short fix of adding \ns in the help output, and propose this for merging again.

Member Author

gasche commented Apr 10, 2018 • edited

 @damiendoligez, I believe that your changes have been addressed. Would you approve the PR? My plan would be to merge into trunk (not 4.07) once the CI passes, to be done with this change.

damiendoligez approved these changes Apr 24, 2018

 \item["-config-var" \var{var}] Print the value of a specific configuration variable from the "-config" output, then exit. If the variable does not exist, the exit code is non-zero. This option is only available since OCaml 4.07,

damiendoligez Apr 24, 2018

Member

You'll have to change this to 4.08 :-(

gasche Apr 24, 2018 • edited

Author Member

Thanks for the catch, I changed it and rebased the PR.

gascheforce-pushed the gasche:config-var branch 3 times, most recently from b38af78 to 6a47aa3Apr 24, 2018

 ocamlc -config: new -config-var option to print specific configuratio… 
…n variables

The proposed behavior of -config-var s is as follows:
- if s is an existing configuration variable, print its value as
a string and exit with a success return value (0)
- if s is not an existing configuration variable, print nothing
and exit with a failure return value (non-0)

Note that we do not print a newline after the value of the
configuration variable. In particular, if the value is an empty
string, the output is undistinguishable from the output for
non-existing variables, the return value has to be considered instead.

The following alternative behaviors were considered:

- We could print a newline after the configuration value, which
would let users distinguish empty values from non-existing variables
by counting the lines of output, and would also be more pleasant for
users invoking the option from the command-line. However, the way
bash works on Windows means that $(ocamlc -config-var foo) would keep a trailing \r in its output, and portable scripts would have to use$(ocamlc -config-var foo | tr -d '\r') instead, which is a pain.
(This issue was pointed out by David Allsopp)

- We could print a message on the error output if the configuration
variable does not exist. This is clearer to a human user, but it is
annoying for scripts if they forget to silence the error output and
get their output mixed with our error messages. The main use of this
new feature is for scripting purposes.
 559206b 

gasche merged commit 832a3ec into ocaml:trunk Apr 30, 2018 2 checks passed

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

Open