Skip to content

Erlang application to watch and reload changed application beam files

License

Notifications You must be signed in to change notification settings

raghavkarol/erl-watch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 Cannot retrieve latest commit at this time.

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

erl-watch

Erlang application to watch and reload changed beam files into an erlang node. Only loads beam files that are in a directory returned by code:get_path() after removing code:lib_dir() applications.

Depends on fswatch for notifications and therefore scales for large projects.

The environment variable WATCH_DIRS a : separated list of directories controls which directories to watch. Changing WATCH_DIRS requires the watch application to be restarted.

This application does not watch and recompile changes to sources because:

  • build systems and commands vary wildly between projects.
  • recompiling does not need an erlang node.

Using with rebar

Add as a dependency to application and ensure the application is started. Dynamic Rebar Configuration might be useful here.

Using directly

  • compile using make compile
  • add ebin directory to your code path e.g., erl -pa .../erl-watch/ebin' -pa ...
  • application:start(watch)

Example Usage

cat .../rel/riak/.erlang

%% Adding current projects ebin directories
[code:add_patha(Dep) || Dep <- filelib:wildcard("../../deps/*/ebin")].
[code:add_patha(Dep) || Dep <- filelib:wildcard("../../apps/*/ebin")].
[code:add_patha(Dep) || Dep <- filelib:wildcard("../deps/*/ebin")].
[code:add_patha(Dep) || Dep <- filelib:wildcard("../apps/*/ebin")].
[code:add_patha(Dep) || Dep <- filelib:wildcard("deps/*/ebin")].
[code:add_patha(Dep) || Dep <- filelib:wildcard("apps/*/ebin")].
[code:add_patha(Dep) || Dep <- filelib:wildcard("ebin")].

%% Starting applications
application:start(watch).

WATCH_DIRS=$(pwd) .../rel/riak/bin/riak console # WATCH_DIRS=<dir1>:<dir2> watches <dir1> and <dir2> for changes

Suggestion for Auto-recompilation

I use watchdog like this:

 CMD='rebar compile'
 watchmedo shell-command \
          --patterns="*.erl;*.hrl;*.dot" \
          --wait \
          --recursive \
          --command="${CMD}"

About

Erlang application to watch and reload changed application beam files

Resources

License

Stars

Watchers

Forks

Packages

No packages published