diff options
author | Tomas Abrahamsson <tomas.abrahamsson@gmail.com> | 2013-12-17 12:59:15 +0100 |
---|---|---|
committer | Tomas Abrahamsson <tomas.abrahamsson@gmail.com> | 2014-10-29 23:45:35 +0100 |
commit | 0caf047fc3d978189e12dc398d06472eb3d236ad (patch) | |
tree | 97102fe5648a7225cbd7ab1fb50614639894c226 /src/rebar_protobuffs_compiler.erl | |
parent | b92dce156933eda5b79f0ed6c59beb1a07b33876 (diff) | |
download | rebar-0caf047fc3d978189e12dc398d06472eb3d236ad.tar.gz |
Introduce pluggable protocol buffer compilers
Make it possible for plug in alternative protocol buffer compilers.
The compilers are picked up based on if they export all of the
functions key/0, proto_compile/3, proto_clean/3 and proto_info/2.
The set of compiler modules to choose from, is fetched from the rebar
application environment, from the app_dir modules.
A new config option, {proto_compiler,Compiler}, specifies which of
the available protocol buffer compilers to use. The 'protobuffs'
compiler is now one such compiler (the only one), and it is also the
default, for backwards compatibility.
Diffstat (limited to 'src/rebar_protobuffs_compiler.erl')
-rw-r--r-- | src/rebar_protobuffs_compiler.erl | 73 |
1 files changed, 32 insertions, 41 deletions
diff --git a/src/rebar_protobuffs_compiler.erl b/src/rebar_protobuffs_compiler.erl index e89c700..2b0b621 100644 --- a/src/rebar_protobuffs_compiler.erl +++ b/src/rebar_protobuffs_compiler.erl @@ -26,11 +26,12 @@ %% ------------------------------------------------------------------- -module(rebar_protobuffs_compiler). --export([compile/2, - clean/2]). +-export([key/0, + proto_compile/3, + proto_clean/3]). %% for internal use only --export([info/2]). +-export([proto_info/2]). -include("rebar.hrl"). @@ -38,58 +39,48 @@ %% Public API %% =================================================================== -compile(Config, _AppFile) -> - case rebar_utils:find_files("src", "^[^._].*\\.proto$") of - [] -> - ok; - FoundFiles -> - %% Check for protobuffs library -- if it's not present, fail - %% since we have.proto files that need building - case protobuffs_is_present() of - true -> - %% Build a list of output files - { Proto, Beam, Hrl } - Targets = [{Proto, beam_file(Proto), hrl_file(Proto)} || - Proto <- FoundFiles], - - %% Compile each proto file - compile_each(Config, Targets); - false -> - ?ERROR("Protobuffs library not present in code path!\n", - []), - ?FAIL - end +key() -> + protobuffs. + +proto_compile(Config, _AppFile, ProtoFiles) -> + %% Check for protobuffs library -- if it's not present, fail + %% since we have.proto files that need building + case protobuffs_is_present() of + true -> + %% Build a list of output files - { Proto, Beam, Hrl } + Targets = [{Proto, beam_file(Proto), hrl_file(Proto)} || + Proto <- ProtoFiles], + + %% Compile each proto file + compile_each(Config, Targets); + false -> + ?ERROR("Protobuffs library not present in code path!\n", + []), + ?FAIL end. -clean(_Config, _AppFile) -> +proto_clean(_Config, _AppFile, ProtoFiles) -> %% Get a list of generated .beam and .hrl files and then delete them - Protos = rebar_utils:find_files("src", ".*\\.proto$"), - BeamFiles = [fq_beam_file(F) || F <- Protos], - HrlFiles = [fq_hrl_file(F) || F <- Protos], + BeamFiles = [fq_beam_file(F) || F <- ProtoFiles], + HrlFiles = [fq_hrl_file(F) || F <- ProtoFiles], Targets = BeamFiles ++ HrlFiles, - case Targets of - [] -> - ok; - _ -> - delete_each(Targets) - end. + delete_each(Targets). %% =================================================================== %% Internal functions %% =================================================================== -info(help, compile) -> - info_help("Build Protobuffs (*.proto) sources"); -info(help, clean) -> - info_help("Delete Protobuffs (*.proto) build results"). +proto_info(help, compile) -> + info_help(); +proto_info(help, clean) -> + info_help(). -info_help(Description) -> +info_help() -> ?CONSOLE( - "~s.~n" - "~n" "Valid rebar.config options:~n" " erl_opts is passed as compile_flags to " "protobuffs_compile:scan_file/2~n", - [Description]). + []). protobuffs_is_present() -> code:which(protobuffs_compile) =/= non_existing. |