alavrik / piqi

Piqi – universal schema language: JSON, XML, Protocol Buffers data validation and conversion
http://piqi.org
Apache License 2.0
246 stars 36 forks source link

Appending _piqi in module naming prevents from using ocamlbuild to handle piqi files #3

Closed williamleferrand closed 13 years ago

williamleferrand commented 13 years ago

Hi Anton,

May I suggest that you remove, in piqic_ocaml_base.ml, the operation that appends a _piqi to the imported modules? This renaming breaks ocamlbuild support for piqi in a very bad manner ..

thx!

william

alavrik commented 13 years ago

Hi William,

This is just the default behavior -- the output file name can be customized. There are two ways of doing it:

  1. This is an ad-hoc method. Use -o argument for piqic ocaml command, e.g.

    piqic ocaml -o m.ml m.piqi

  2. This method is recommended in general. In your m.piqi define the top-level ocaml-module property:

    .ocaml-module "M"

I've spent fair amount of time thinking about it and after using the system myself for a while I decided to make this behavior the default. Adding prefixes is very conventional across data serialization systems, but more importantly, it is very useful and practical.

Anton

alavrik commented 13 years ago

BTW, I don't use ocamlbuild as I prefer good old makefiles and OCamlMakefile. But I guess the way how automatic rules work in ocamlbuild should be similar.

The problem with creating automatic rules for piqic in makefiles or ocamlbuild is that they are not reliable enough. For example, name of a .piqi file can contain - which piqic ocaml will automatically convert to _ when generating the output .ml file. This will likely break the automatic rule. Also there could be similar problems with capitalized modules. I don't know how you solved it in ocamlbuild in a generic way, but for makefiles I just ended up listing all compilation targets for piqic ocaml manually and it works beautifully. For example:

PIQI_ML_SOURCES = <list of .ml files that you get from the list of .piqi files>
....
$(PIQI_ML_SOURCES): *.piqi
    for i in $^; do \
        piqic ocaml $$i; \
    done
williamleferrand commented 13 years ago

hi Anton,

ok, thanks for the info and the tip!