Rewrite to use the new rb-inotify API

This commit is contained in:
Paul van Tilburg 2018-06-22 20:07:26 +02:00
parent 96a6d3533c
commit 712b17c308
1 changed files with 5 additions and 10 deletions

View File

@ -186,20 +186,15 @@ end
## Main event loop ## Main event loop
# Add input file with dependancies to the watch list and start event loop. # Add input file with dependancies to the watch list and start event loop.
i = INotify::Notifier.new notifier = INotify::Notifier.new
dirs = files.map { |file| File.dirname(file) } dirs = files.map { |file| File.dirname(file) }
dirmap = {}
dirs.each do |dir| dirs.each do |dir|
# Use a watch descriptor per directory and save it for later. # Set up a watch per directory
wd = i.add_watch(dir, Inotify::CLOSE_WRITE) notifier.watch(dir, :close_write) do
dirmap[wd] = dir
end
# Process the events, recompile and reload when necessary.
i.each_event do |ev|
# Only recompile if files are modified that we are interested in.
if files.include?(dirmap[ev.wd] + "/" + ev.name)
puts "I: file #{ev.name} modified, compiling #{infile}..." puts "I: file #{ev.name} modified, compiling #{infile}..."
compile(infile, mode) compile(infile, mode)
reload(infile, mode) reload(infile, mode)
end end
end end
notifier.run