On Wed, May 22, 2013 at 01:29:13AM -0500, Anton Lavrik wrote:
> Hi Motiejus,
>
> Don't get me wrong -- I'm totally fine with your decision to work on rebar
> plugin for piqi. And I will try to help if you need any changes in the piqi
> compiler.
Thank you, this is great.
> Overall, I think that rebar is a useful and generally nice tool. The fact
> protobuffs and erlydtl compilers are built-in means they can't be extended
> easily and also they are turned on by default which is not always the
> desired behavior. This is likely an early design mistake that nobody
> really cares about fixing.
Sure. Normally these should be in the plugin. However, it was not
cleanly possible until[1] to do it using plugin, so they did a built-in.
> More importantly, with rebar plugins like that you are inevitably
> introducing another notation and a layer for modifying the behavior of
> a build tool, in this case, piqic-erlang. Such layer needs to be
> documented, kept in sync with up-stream features and so on. Makefiles
> don't have that problem. But again, I can see the reasons why you want
> to have the rebar plugin.
I do not see the difference from Makefile here. Both hold the same
requirements. Keeping the external interfaces documented and stable-ish
is the same as keeping the command-line arguments stable-ish.
> Anyway... The approach you suggested in your first email won't work
> out of the box, because although piqic-erlang knows the names of .hrl
> and .erl artifacts generated for .piqi dependencies, it doesn't really
> know the directory in which these files where generated. It only knows
> directories of the source .piqi files it loads. The output directory
> is totally up to you. By default it is CWD and you can modify it using
> -O command-line option.
I do not understand the paragraph above. First, you probably meant `-C`
for output directory?
piqi-erlang$ ERL_LIBS=.. ./piqic-erlang/piqic-erlang --help
Usage: ./piqic-erlang/piqic-erlang [options] <.piqi file>
Options:
...
-C <output directory> specify output directory
...
I uploaded the WIP plugin to github[2]. Essentially it invokes
piqic_erlang:piqic_erlang/2, just like piqic-erlang/src/piqic_erlang.erl
does. Now the plugin is a silly Makefile replacement, and I want to keep
it that way. Ideally it should not require anything from the compiler,
only what is possible to be sent (and received) via command line. That
will make the plugin really well decoupled from piqic-erlang internals.
Since the plugin specifies the output directory, I do not see a problem
here.
> Let's see what how the compiler could help. For example, piqic-erlang
> could generate a list of {source directory, erlang module name} pairs
> and you could derive full output paths and include_lib paths of the
> artifacts from that.
Please elaborate. What would be source directory and erlang module name?
I was thinking about something like this. If piqic-erlang would return a
list of tuples. In pseudo-spec:
-spec piqic_erlang(..., ...) -> {ok, [T]} | {error, list()} where
T = {"priv/defn.piqi", ["defn_piqi.erl"], ["defn_piqi.hrl"]}
Where first key is piqi input file, and second and third elements are
filenames generated from that piqi input file without the directory name
(plugin will know the output directory: it's either cwd(), or "-C").
That way plugin will be able to do any kind of nasty hacks to make the
dependencies right. Most importantly, in whatever language.
> Another way is to implement the transformation
> you described by using a user-defined callback module called by
> piqic-erlang.
Two things against this:
1. if someone will want to make an Ant plugin, she will not have this
functionality unless she makes an Erlang wrapper which calls Ant.
Ugly.
2. I do not have a clear idea what the callback could do.
> Which approach do you like better? Can you think of better ways?
First one. To make it compatible with CMake/Ant/Whatever plugins, we
have to expose the above from piqic-erlang executable as well. For
example, if "-v" is passed, then piqic-erlang executable will output
these tuples to standard-output (prefixed probably, so it can be easily
distinguished from other verbose messages), so other plugin writers can
parse it and use it just like my plugin could.
Also, piqic_erlang:piqic_erlang now will have to return
{ok, [T]} | {error, Msg}
instead of
'ok' | {error, Msg}
for the reasons mentioned above.
I am CCing Ignas, because he often thinks out of the box and might
propose something even cleaner; what is more, he will be one of the
first plugin users.
Hope you are enjoying your holiday!
Motiejus
[1]:
https://github.com/rebar/rebar/commit/252b31f2a4b95670ef75a6a712788af977e869e9
[2]:
https://github.com/Motiejus/piqi-rebar-plugin