/fs_sync

Recompile Erlang modules on the fly (yet another, yes)

Primary LanguageErlang

FS Sync

Monitors file system events using fs_event and recompiles .erl files on the fly using compile:file/2, reloads beam files by code:load_binary/3.

Syncer

fs_sync:start("/cool/erlang/project/").
fs_sync:start()/go().
fs_sync:stop().
fs_sync:watch(Path).
fs_sync:unwatch(Path).

fs_sync:go/0 tries to guess project root (e.g. goes two level up from _rel folder).

Tracer

fs_tracer:go().
fs_tracer:add(Module, Function).
fs_tracer:del(Module, Function).
fs_tracer:list().
fs_tracer:clear().

Enables tracing for specific functions. Tracing is enabled on all processes.

Sample output:

(fs_sync@127.0.0.1)1> fs_tracer:go().
(fs_sync@127.0.0.1)2> fs_tracer:add(lists, seq).
(fs_sync@127.0.0.1)3> spawn(fun() -> X = lists:seq(1,5) end).
TRACE: lists:seq/2 <- [1,5]
TRACE: lists:seq/2 -> [1,2,3,4,5]

Please note that when module is reloaded (e.g. with fs_sync), then tracing is resetted.

Tracer formatter

To process trace arguments (think of huge erlang structs) one can use a formatter function:

fs_tracer:formatter(fun(X) -> X end).

This function will be applied to each function argument one by one, and to function result. There is a built-in formatter to hide records by their names:

fs_tracer:formatter(fun tracer_fmt:hide_records/1).

External handlers

File type is determined by file extension. Natively handled types are "erl" and "beam". It is possible to define an external type handler for unknown file types as default_handler parameter (script will be executed in erlang node cwd), and an external handler to execute after internal handler -- after_handler parameter. External handlers are called with Erlang os:cmd/1, with type and filename provided as command line arguments, see example/handler.sh.

Configuration options

Complete documented configuration file sys.config.

  • skip_types -- list of file extensions to ignore completely
  • synthesize_beam_event -- a helper for naive fs_event scanner, to reload beam file immediately after compilation
  • after_handler -- see External handlers
  • default_handler -- see External handlers

Future plans

  1. Integrate with fs_sync (e.g. re-apply tracing on module reload)
  2. Maybe handle .hrl changes as well, a-la @choptastics sync
  3. Have examples for external tools (rebar, namely)