1 %%%-------------------------------------------------------------------
2 %%% @author Eric Merritt <>
3 %%% @copyright (C) 2011, Eric Merritt
7 %%% Created : 15 Apr 2011 by Eric Merritt <>
8 %%%-------------------------------------------------------------------
9 -module(sin_compile_erl
).
12 -export([build_file
/5,
16 -include_lib("sinan/include/sinan.hrl").
18 %%%===================================================================
20 %%%===================================================================
21 get_target(BuildDir
, File
, ".erl") ->
22 sin_task_build:get_target(File
, ".erl", BuildDir
, ".beam").
24 %% @doc Do the actual compilation on the file.
25 -spec
build_file(sin_config:matcher(), sin_state:state(),
26 sin_file_info:mod(), [term()], string()) ->
27 {module(), sin_config:config()}.
28 build_file(Config
, State
, Module
=#module
{path
=File
}, Options
, _Target
) ->
29 sin_log:verbose(Config
, "Building ~s", [File
]),
30 case compile:file(File
, Options
) of
32 reload_module(ModuleName
),
34 {ok
, ModuleName
, []} ->
35 reload_module(ModuleName
),
37 {ok
, ModuleName
, Warnings0
} ->
38 reload_module(ModuleName
),
39 Warnings1
= sin_task_build:gather_fail_info(Warnings0
, "warning"),
41 {build_warnings
, Warnings1
}),
43 {error
, Errors
, Warnings
} ->
45 lists:flatten([sin_task_build:gather_fail_info(Errors
,
47 sin_task_build:gather_fail_info(Warnings
,
49 sin_log:normal(Config
, lists:flatten(ErrorStrings
)),
50 ?
SIN_RAISE(State
, {build_error
, error_building_erl_file
, File
});
52 sin_log:normal(Config
, "Unknown error occured during build"),
53 ?
SIN_RAISE(State
, {build_error
, error_building_erl_file
, File
})
56 %% @doc Format an exception thrown by this module
57 -spec
format_exception(sin_exceptions:exception()) ->
59 format_exception(Exception
) ->
60 sin_exceptions:format_exception(Exception
).
61 %%%===================================================================
62 %%% Internal functions
63 %%%===================================================================
64 %% We don't want to do this on ourselves
65 -spec
reload_module(atom()) -> {ok
, atom()}.
67 when not Module
== ?MODULE
->
69 code:load_file(Module
),
71 code:load_file(Module
);