@@ -47,24 +47,31 @@ proto_compile(Config, _AppFile, _ProtoFiles) ->
47
47
% % since we have.proto files that need building
48
48
case gpb_is_present () of
49
49
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 ],
50
54
rebar_base_compiler :run (Config , [],
51
- " src" , " .proto" ,
52
- " src" , " .erl" ,
55
+ lists :zip (Files , Targets ),
53
56
fun compile_gpb /3 ,
54
57
[{check_last_mod , true }]);
55
58
false ->
56
59
? ERROR (" The gpb library is not present in code path!\n " , []),
57
60
? FAIL
58
61
end .
59
62
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
+
60
69
proto_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 (),
64
71
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 ]),
68
75
ok .
69
76
70
77
% % ===================================================================
@@ -82,37 +89,55 @@ proto_info(help, compile) ->
82
89
proto_info (help , clean ) ->
83
90
? CONSOLE (" " , []).
84
91
85
- gpb_opts (Config ) ->
86
- rebar_config :get_local (Config , gpb_opts , []).
87
-
88
92
gpb_is_present () ->
89
93
code :which (gpb ) =/= non_existing .
90
94
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
+
91
101
compile_gpb (Source , _Target , Config ) ->
92
102
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 ),
96
105
ok = filelib :ensure_dir (filename :join (" ebin" , " dummy" )),
97
106
ok = filelib :ensure_dir (filename :join (" include" , " dummy" )),
98
107
case gpb_compile :file (SourceFullPath , GpbOpts ) of
99
108
ok ->
100
109
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 ]),
103
113
? FAIL
104
114
end .
105
115
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 ).
108
121
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 ).
111
125
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 ).
114
129
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 , " " ),
117
134
filename :join ([Dir , Prefix ++ BaseNoExt ++ Suffix ++ NewExt ]).
118
135
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