Skip to content

Instantly share code, notes, and snippets.

@kevsmith
Created April 10, 2010 16:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kevsmith/362091 to your computer and use it in GitHub Desktop.
Save kevsmith/362091 to your computer and use it in GitHub Desktop.
#!/bin/sh
erlc flymake.erl
echo "#!/usr/bin/env escript" > eflymake
cat flymake.beam >> eflymake
chmod +x eflymake
-module(flymake).
-export([main/1]).
-define(REBARS, ["..", "../../.."]).
file_exists(FileName) ->
case file:read_file_info(FileName) of
{error, _} ->
false;
_ ->
true
end.
locate_build_tool([]) ->
not_found;
locate_build_tool([H|T]) ->
case file_exists(filename:join([H, "rebar"])) of
true ->
H;
false ->
locate_build_tool(T)
end.
manual_compile(FileName) ->
compile:file(FileName, [warn_obsolete_guard, warn_unused_import,
warn_shadow_vars, warn_export_vars,
strong_validation, report,
{i, "../include"},
{outdir, "/tmp"}]).
normalize_rebar_error(Err, FileName) ->
[_|T] = string:tokens(Err, ":"),
string:join([FileName|T], ":").
rebar_build(FileName, Path) ->
file:set_cwd(Path),
Cmd = "./rebar compile 2>&1",
[_|T] = string:tokens(os:cmd(Cmd), "\n"),
Errors = [normalize_rebar_error(Err, FileName) || Err <- T],
io:format("~s", [string:join(Errors, "\n") ++ "\n"]).
main([FileName]) ->
case locate_build_tool(?REBARS) of
not_found ->
manual_compile(FileName);
Rebar ->
rebar_build(FileName, Rebar)
end.
1) Use build_flymake.sh to compile flymake.erl into the eflymake script.
2) Replace your existing eflymake script with the newly built one.
NOTE: Don't forget to make a back up copy of your original eflymake in case this one has bugs!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment