NO, this is all wrong! I was testing against the wrong version of ppx_deriving
. OOPS!
Interesting. I had noticed that the PPX-expanded version of the file that dune creates, had this “context” at its start:
[@@@ocaml.ppx.context
{
tool_name = "ppx_driver";
include_dirs = [];
hidden_include_dirs = [];
load_path = ([], []);
open_modules = [];
for_package = None;
debug = false;
use_threads = false;
use_vmthreads = false;
recursive_types = false;
principal = false;
transparent_modules = false;
unboxed_types = false;
unsafe_string = false;
cookies = []
}]
but since it contained nothing special, I just ignored it. But now, based on your pointer, I put this bit of text into the source file, and ran the same ocamlfind command from my previous post (that previously gave an error) and now it no longer gives an error.
So I’m concluding that the way that dune invokes PPX rewriters, is by first prepending this “context”, and then invoking the rewriters, in whatever order is specified. But ocamlfind doesn’t prepend this context, hence the differing behaviour.
I don’t know where to open a bug, or even whether anybody who maintains ppxlib cares.
I don’t use ppxlib or the standard PPX infrastructure: I develop and maintain a comprehensive PPX rewriter infrastructure based on Camlp5 (pa_ppx
and a bunch of other packages), that is completely independent of ppxlib. The only reason I even found this discrepancy, is that I keep pa_ppx
compatible with the standard PPX rewriters, by running the standard unit-tests, copied-over from the standard PPX rewriter sources. So I build and run those unit-tests, but since pa_ppx
is entirely Makefile-based, obviously I bumped into this “interesting” bug.
One last thing: I see in that comment
(* Cannot use main_module_name from code_path because that contains .cppo suffix (via line directives), so it's actually not the module name. *)
that somehow if a file test.cppo.ml
is preprocessed to produce test.ml
, then the module-name will be derived from test.ml
and not from test.cppo.ml
. But this seems wrong: the convention almost everywhere I’ve ever worked with languages that support #line
directives, is that the original source filename is what should be used whenever something needs the file-name (hence, the module-name).