11-module (rebar3_clojerl_prv_compile ).
22
3+ -include (" rebar3_clojerl.hrl" ).
4+
35-export ([init /1 , do /1 , format_error /1 ]).
46
57-define (PROVIDER , compile ).
68-define (NAMESPACE , clojerl ).
79-define (DEPS , [{default , compile }]).
8- -define (DEFAULT_SRC_DIRS , [" src" ]).
9-
10- -define (CLOJERL , <<" clojerl" >>).
11- -define (CLJINFO_FILE , <<" cljinfo" >>).
1210
1311-type config () :: #{ ebin_dir => file :name ()
1412 , protocols_dir => file :name ()
@@ -38,10 +36,10 @@ init(State) ->
3836do (State ) ->
3937 DepsPaths = rebar_state :code_paths (State , all_deps ),
4038 ok = code :add_pathsa (DepsPaths ),
41- ok = ensure_clojerl (State ),
39+ ok = rebar3_clojerl_utils : ensure_clojerl (State ),
4240
43- AllApps = all_apps (State ),
44- Apps = lists : filter ( is_not_dep_name_fun ( ? CLOJERL ), AllApps ),
41+ AllApps = rebar3_clojerl_utils : all_apps (State ),
42+ Apps = rebar3_clojerl_utils : filter_app ( AllApps , ? CLOJERL ),
4543 Config = #{protocols_dir => protocols_dir (State )},
4644
4745 restore_duplicates (AllApps ),
@@ -58,10 +56,6 @@ format_error(Reason) ->
5856% % Internal functions
5957% % =============================================================================
6058
61- -spec all_apps (rebar_state :t ()) -> [rebar_app_info :t ()].
62- all_apps (State ) ->
63- lists :usort (rebar_state :all_deps (State )) ++ rebar_state :project_apps (State ).
64-
6559-spec protocols_dir (rebar_state :t ()) -> file :name ().
6660protocols_dir (State ) ->
6761 % % Get the first application from this project.
@@ -134,32 +128,6 @@ update_app_file({Dir, Filepaths}) ->
134128 [] -> ok
135129 end .
136130
137- -spec ensure_clojerl (rebar_state :t ()) -> ok .
138- ensure_clojerl (State ) ->
139- case find_dep (State , ? CLOJERL ) of
140- notfound ->
141- rebar_api :abort (" Clojerl was not found as a dependency" , []);
142- {ok , _ } ->
143- ok = clojerl :start ()
144- end .
145-
146- -spec find_dep (rebar_state :t (), binary ()) -> notfound | {ok , any ()}.
147- find_dep (State , Name ) ->
148- Deps = rebar_state :all_deps (State ),
149- case lists :filter (is_dep_name_fun (Name ), Deps ) of
150- [] -> notfound ;
151- [DepInfo ] -> {ok , DepInfo }
152- end .
153-
154- -spec is_dep_name_fun (binary ()) -> fun ((_ ) -> boolean ()).
155- is_dep_name_fun (Name ) ->
156- fun (Dep ) -> Name =:= rebar_app_info :name (Dep ) end .
157-
158- -spec is_not_dep_name_fun (binary ()) -> fun ((_ ) -> boolean ()).
159- is_not_dep_name_fun (Name ) ->
160- IsDepName = is_dep_name_fun (Name ),
161- fun (Dep ) -> not IsDepName (Dep ) end .
162-
163131-spec compile (rebar_app_info :t (), config ()) -> boolean ().
164132compile (AppInfo , Config0 ) ->
165133 Graph = load_graph (AppInfo ),
@@ -200,7 +168,9 @@ compile_clje(Src, Config) ->
200168 catch
201169 _ :Reason ->
202170 Stacktrace = erlang :get_stacktrace (),
203- rebar_api :debug (" Stacktrace:~n~s " , [clj_utils :stacktrace (Stacktrace )]),
171+ rebar_api :debug ( " Stacktrace:~n~s "
172+ , [clj_utils :format_stacktrace (Stacktrace )]
173+ ),
204174 rebar_api :abort ( " Error while compiling ~s : ~s "
205175 , [Src , clj_rt :str (Reason )]
206176 )
@@ -280,7 +250,7 @@ find_files_to_compile(AppInfo, Config) ->
280250 , digraph :graph ()
281251 ) -> [{file :name (), file :name ()}].
282252find_files_to_compile (SrcDir , EbinDirs , ProtoDir , Graph ) ->
283- SrcFiles = rebar_utils :find_files (SrcDir , " clj[ce]" ),
253+ SrcFiles = rebar_utils :find_files (SrcDir , " . clj[ce]" ),
284254 [ {SrcDir , Source }
285255 || Source <- SrcFiles ,
286256 should_compile_file (Source , SrcDir , EbinDirs , ProtoDir , Graph )
0 commit comments