You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current ocamlbuild support for -pp flags is not satisfying for preprocessing commands that need user-passed arguments. It is possible to pass "-pp foo" and "-ppflag foo" to the command-line invocation of ocamlbuild, but they will replace the preprocessor invocation command instead of being appended to it.
Consider the following file test.ml:
IFDEF FOO THEN
print_endline "foo"
ELSE
print_endline "bar"
ENDIF
The following will work:
ocamlbuild -tag "pp(camlp4of -DFOO)" test.byte
the following will also work:
ocamlbuild -ppflag camlp4of -ppflag -DFOO test.byte
they both generate the command
.../ocamlc.opt -c -pp 'camlp4of -DFOO' -o test.cmo test.ml # cached
but the following will fail:
ocamlbuild -use-ocamlfind -tag "syntax(camlp4o)" -package camlp4.macro -ppflag -DFOO test.byte
/usr/bin/ocamlfind ocamldep -package camlp4.macro -syntax camlp4o -pp -DFOO -modules test.ml > test.ml.depends
Warning: -pp overrides the effect of -syntax partly
sh: 0: Illegal option -D
Preprocessing error on file test.ml
It would be useful to directly support ocamlfind's -ppopt option
(when -use-ocamlfind is used), that doesn't replace the preprocessor
command entirely but only appends to it. One would then be able to do
(I'm using below the new "-syntax" command-line option corresponding
to the flag):
ocamlbuild -use-ocamlfind -syntax camlp4o -package camlp4.macro -ppopt -DFOO test.byte
Of course, it is important to also have a "ppopt(-DFOO)" parametrized
flag to be able to use it locally.
Note that, as a workaround, it is currently possible to pass -ppopt as
a -cflags parameter:
ocamlbuild -use-ocamlfind -syntax camlp4o -package camlp4.macro -cflags -ppopt,-DFOO test.byte
The problem is that only works during "compile" steps, and will not
work, for example, when building a .pp.ml target.
(In the long-term it is unclear to me whether having both -ppflag and -ppopt is useful, and we should not use the appending semantics of -ppopt for -ppflag as well. This would have backward-compatibility implications though, so it's better left for later.)
The text was updated successfully, but these errors were encountered:
Original bug ID: 6103
Reporter: @gasche
Status: resolved (set by @damiendoligez on 2017-03-01T15:23:06Z)
Resolution: suspended
Priority: normal
Severity: feature
Category: -for ocamlbuild use https://github.com/ocaml/ocamlbuild/issues
Tags: junior_job
Bug description
The current ocamlbuild support for -pp flags is not satisfying for preprocessing commands that need user-passed arguments. It is possible to pass "-pp foo" and "-ppflag foo" to the command-line invocation of ocamlbuild, but they will replace the preprocessor invocation command instead of being appended to it.
Consider the following file test.ml:
IFDEF FOO THEN
print_endline "foo"
ELSE
print_endline "bar"
ENDIF
The following will work:
ocamlbuild -tag "pp(camlp4of -DFOO)" test.byte
the following will also work:
ocamlbuild -ppflag camlp4of -ppflag -DFOO test.byte
they both generate the command
.../ocamlc.opt -c -pp 'camlp4of -DFOO' -o test.cmo test.ml # cached
but the following will fail:
ocamlbuild -use-ocamlfind -tag "syntax(camlp4o)" -package camlp4.macro -ppflag -DFOO test.byte
Warning: -pp overrides the effect of -syntax partly
sh: 0: Illegal option -D
Preprocessing error on file test.ml
It would be useful to directly support ocamlfind's -ppopt option
(when -use-ocamlfind is used), that doesn't replace the preprocessor
command entirely but only appends to it. One would then be able to do
(I'm using below the new "-syntax" command-line option corresponding
to the flag):
ocamlbuild -use-ocamlfind -syntax camlp4o -package camlp4.macro -ppopt -DFOO test.byte
Of course, it is important to also have a "ppopt(-DFOO)" parametrized
flag to be able to use it locally.
Note that, as a workaround, it is currently possible to pass -ppopt as
a -cflags parameter:
ocamlbuild -use-ocamlfind -syntax camlp4o -package camlp4.macro -cflags -ppopt,-DFOO test.byte
The problem is that only works during "compile" steps, and will not
work, for example, when building a .pp.ml target.
(In the long-term it is unclear to me whether having both -ppflag and -ppopt is useful, and we should not use the appending semantics of -ppopt for -ppflag as well. This would have backward-compatibility implications though, so it's better left for later.)
The text was updated successfully, but these errors were encountered: