Skip to content

Instantly share code, notes, and snippets.

@dysinger
Created December 18, 2009 16:52
Show Gist options
  • Select an option

  • Save dysinger/259607 to your computer and use it in GitHub Desktop.

Select an option

Save dysinger/259607 to your computer and use it in GitHub Desktop.
%% -------------------------------------------------------------------
%%
%% rebar: Erlang Build Tools
%%
%% Copyright (c) 2009 Dave Smith (dizzyd@dizzyd.com),
%% Tim Dysinger (tim@dysinger.net)
%%
%% Permission is hereby granted, free of charge, to any person obtaining a copy
%% of this software and associated documentation files (the "Software"), to deal
%% in the Software without restriction, including without limitation the rights
%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
%% copies of the Software, and to permit persons to whom the Software is
%% furnished to do so, subject to the following conditions:
%%
%% The above copyright notice and this permission notice shall be included in
%% all copies or substantial portions of the Software.
%%
%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
%% THE SOFTWARE.
%% -------------------------------------------------------------------
-module(rebar_lfe_compiler).
-export([compile/2]).
%% ===================================================================
%% Public API
%% ===================================================================
compile(Config, _AppFile) ->
%% TODO check if we even have the lfe_comp compiler in our path 1st
rebar_erlc_compiler:do_compile(Config, "src/*.lfe", "ebin", ".lfe", ".beam",
fun compile_lfe/2,
rebar_config:get_list(Config,
erl_first_files, [])).
%% ===================================================================
%% Internal functions
%% ===================================================================
compile_lfe(Source, Config) ->
Opts = [{i, "include"}, {outdir, "ebin"}, report, return] ++
compile_opts(Config, erl_opts),
case eval("lfe_comp:file(Source,Opts]).",
[{'Source',Source},{'Opts',Opts}]) of
{ok,_} -> ok;
%% TODO does LFE even have warnings?
_ -> ?FAIL
end.
eval(Code,Args) ->
{ok,Scanned,_} = erl_scan:string(Code),
{ok,Parsed} = erl_parse:parse_exprs(Scanned),
Bindings = lists:foldl(fun({Key,Val},Acc) ->
erl_eval:add_binding(Key,Val,Acc)
end,erl_eval:new_bindings(),Args),
{value,Result,_} = erl_eval:exprs(Parsed,Bindings),
Result.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment