@@ -47,24 +47,31 @@ proto_compile(Config, _AppFile, _ProtoFiles) ->
4747 % % since we have.proto files that need building
4848 case gpb_is_present () of
4949 true ->
50+ GpbOpts = user_gpb_opts (Config ),
51+ Files = rebar_utils :find_files_by_ext (" src" , " .proto" ),
52+ Targets = [filename :join (" src" , target_filename (F , GpbOpts ))
53+ || F <- Files ],
5054 rebar_base_compiler :run (Config , [],
51- " src" , " .proto" ,
52- " src" , " .erl" ,
55+ lists :zip (Files , Targets ),
5356 fun compile_gpb /3 ,
5457 [{check_last_mod , true }]);
5558 false ->
5659 ? ERROR (" The gpb library is not present in code path!\n " , []),
5760 ? FAIL
5861 end .
5962
63+ target_filename (ProtoFileName , GpbOpts ) ->
64+ ModulePrefix = proplists :get_value (module_name_prefix , GpbOpts , " " ),
65+ ModuleSuffix = proplists :get_value (module_name_suffix , GpbOpts , " " ),
66+ Base = filename :basename (ProtoFileName , " .proto" ),
67+ ModulePrefix ++ Base ++ ModuleSuffix ++ " .erl" .
68+
6069proto_clean (Config , _AppFile , ProtoFiles ) ->
61- GpbOpts = gpb_opts (Config ),
62- MPrefix = proplists :get_value (module_name_prefix , GpbOpts , " " ),
63- MSuffix = proplists :get_value (module_name_suffix , GpbOpts , " " ),
70+ GpbOpts = user_gpb_opts (Config ) ++ default_dest_opts (),
6471 rebar_file_utils :delete_each (
65- [beam_relpath ( MPrefix , F , MSuffix ) || F <- ProtoFiles ]
66- ++ [erl_relpath ( MPrefix , F , MSuffix ) || F <- ProtoFiles ]
67- ++ [hrl_relpath ( MPrefix , F , MSuffix ) || F <- ProtoFiles ]),
72+ [beam_file ( F , GpbOpts ) || F <- ProtoFiles ]
73+ ++ [erl_file ( F , GpbOpts ) || F <- ProtoFiles ]
74+ ++ [hrl_file ( F , GpbOpts ) || F <- ProtoFiles ]),
6875 ok .
6976
7077% % ===================================================================
@@ -82,37 +89,55 @@ proto_info(help, compile) ->
8289proto_info (help , clean ) ->
8390 ? CONSOLE (" " , []).
8491
85- gpb_opts (Config ) ->
86- rebar_config :get_local (Config , gpb_opts , []).
87-
8892gpb_is_present () ->
8993 code :which (gpb ) =/= non_existing .
9094
95+ user_gpb_opts (Config ) ->
96+ rebar_config :get_local (Config , gpb_opts , []).
97+
98+ default_dest_opts () ->
99+ [{o_erl , " src" }, {o_hrl , " include" }].
100+
91101compile_gpb (Source , _Target , Config ) ->
92102 SourceFullPath = filename :absname (Source ),
93- DefaultDestOpts = [{o_erl , " src" }, {o_hrl , " include" }],
94- SelfIncludeOpt = [{i ,filename :dirname (SourceFullPath )}],
95- GpbOpts = gpb_opts (Config ) ++ DefaultDestOpts ++ SelfIncludeOpt ,
103+ GpbOpts = user_gpb_opts (Config ) ++ default_dest_opts ()
104+ ++ default_include_opts (SourceFullPath ),
96105 ok = filelib :ensure_dir (filename :join (" ebin" , " dummy" )),
97106 ok = filelib :ensure_dir (filename :join (" include" , " dummy" )),
98107 case gpb_compile :file (SourceFullPath , GpbOpts ) of
99108 ok ->
100109 ok ;
101- {error , _Reason } ->
102- ? ERROR (" Failed to compile ~s~n " , [Source ]),
110+ {error , Reason } ->
111+ ReasonStr = gpb_compile :format_error (Reason ),
112+ ? ERROR (" Failed to compile ~s : ~s~n " , [SourceFullPath , ReasonStr ]),
103113 ? FAIL
104114 end .
105115
106- beam_relpath (Prefix , Proto , Suffix ) ->
107- proto_filename_to_relpath (" ebin" , Prefix , Proto , Suffix , " .beam" ).
116+ default_include_opts (SourceFullPath ) ->
117+ [{i ,filename :dirname (SourceFullPath )}].
118+
119+ beam_file (ProtoFile , GpbOpts ) ->
120+ proto_filename_to_path (" ebin" , ProtoFile , " .beam" , GpbOpts ).
108121
109- erl_relpath (Prefix , Proto , Suffix ) ->
110- proto_filename_to_relpath (" src" , Prefix , Proto , Suffix , " .erl" ).
122+ erl_file (ProtoFile , GpbOpts ) ->
123+ ErlOutDir = get_erl_outdir (GpbOpts ),
124+ proto_filename_to_path (ErlOutDir , ProtoFile , " .erl" , GpbOpts ).
111125
112- hrl_relpath (Prefix , Proto , Suffix ) ->
113- proto_filename_to_relpath (" include" , Prefix , Proto , Suffix , " .hrl" ).
126+ hrl_file (ProtoFile , GpbOpts ) ->
127+ HrlOutDir = get_hrl_outdir (GpbOpts ),
128+ proto_filename_to_path (HrlOutDir , ProtoFile , " .hrl" , GpbOpts ).
114129
115- proto_filename_to_relpath (Dir , Prefix , Proto , Suffix , NewExt ) ->
116- BaseNoExt = filename :basename (Proto , " .proto" ),
130+ proto_filename_to_path (Dir , ProtoFile , NewExt , GpbOpts ) ->
131+ BaseNoExt = filename :basename (ProtoFile , " .proto" ),
132+ Prefix = proplists :get_value (module_name_prefix , GpbOpts , " " ),
133+ Suffix = proplists :get_value (module_name_suffix , GpbOpts , " " ),
117134 filename :join ([Dir , Prefix ++ BaseNoExt ++ Suffix ++ NewExt ]).
118135
136+ get_erl_outdir (Opts ) ->
137+ proplists :get_value (o_erl , Opts , get_outdir (Opts )).
138+
139+ get_hrl_outdir (Opts ) ->
140+ proplists :get_value (o_hrl , Opts , get_outdir (Opts )).
141+
142+ get_outdir (Opts ) ->
143+ proplists :get_value (o , Opts , " ." ).
0 commit comments