1 %%%-------------------------------------------------------------------
2 %%% @author Eric Merritt <>
3 %%% @copyright (C) 2011, Eric Merritt
7 %%% Created : 15 Apr 2011 by Eric Merritt <>
8 %%%-------------------------------------------------------------------
9 -module(sin_compile_yrl
).
12 -export([build_file
/5,
16 -include_lib("sinan/include/sinan.hrl").
18 %%%===================================================================
20 %%%===================================================================
21 get_target(BuildDir
, File
, ".yrl") ->
22 sin_task_build:get_target(File
, ".yrl", BuildDir
, ".beam").
24 build_file(Config
, State0
, Module
=#module
{path
=File
}, Options
, Target
) ->
25 ErlFile
= filename:basename(File
, ".yrl"),
26 AppDir
= filename:dirname(Target
),
27 ErlTarget
= filename:join([AppDir
,"src"]),
28 ErlName
= filename:join([ErlTarget
,
29 lists:flatten([ErlFile
, ".erl"])]),
30 sin_log:verbose(Config
, "Building ~s", [File
]),
31 {State2
, ErlModule1
} =
32 case yecc:file(File
, [{parserfile
, ErlName
} |
33 sin_task_build:strip_options(Options
)]) of
35 {State1
, ErlModule0
} = sin_file_info:process_file(State0
, File
, []),
36 sin_compile_erl:build_file(Config
, State1
,
37 rename_path(ErlModule0
, ErlName
),
39 {ok
, _ModuleName
, []} ->
40 {State1
, ErlModule0
} = sin_file_info:process_file(State0
, File
, []),
41 sin_compile_erl:build_file(Config
, State1
, rename_path(ErlModule0
, ErlName
),
43 {ok
, _ModuleName
, Warnings0
} ->
44 Warnings1
= sin_task_build:gather_fail_info(Warnings0
, "warning"),
45 ?
SIN_RAISE(State0
, {build_error
, error_building_yecc
, File
, Warnings1
});
46 {error
, Errors
, Warnings
} ->
47 Errors
= lists:flatten([sin_task_build:gather_fail_info(Errors
,
49 sin_task_build:gather_fail_info(Warnings
,
51 ?
SIN_RAISE(State0
, {build_error
, error_building_yecc
, File
})
53 {State2
, [ErlModule1
, Module
]}.
55 rename_path(Mod
, NewPath
) ->
56 Mod#module
{path
=NewPath
}.
58 %% @doc Format an exception thrown by this module
59 -spec
format_exception(sin_exceptions:exception()) ->
61 format_exception(Exception
) ->
62 sin_exceptions:format_exception(Exception
).
63 %%%===================================================================
64 %%% Internal functions
65 %%%===================================================================