Skip to content

Instantly share code, notes, and snippets.

@bjnortier
Forked from kevsmith/HOWTO.txt
Created October 7, 2010 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjnortier/615014 to your computer and use it in GitHub Desktop.
Save bjnortier/615014 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 skip_deps=true 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