-
Notifications
You must be signed in to change notification settings - Fork 31
/
watchmake
executable file
·47 lines (41 loc) · 1.44 KB
/
watchmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env ruby
# Script to rebuild the project when a file changes.
#
# Runs the make targets given when the script is started.
#
# Usage: ./watchmake examples html
#
# Requires fs-watch. ($ brew install fswatch)
# https://emcrisostomo.github.io/fswatch/getting.html
require "fileutils"
THIS_DIR = File.expand_path("..", __FILE__)
FileUtils.cd THIS_DIR
FSWATCH_COMMAND = "fswatch --latency 0.1 -Ee 'git|build/|elm-stuff/|solver_server/|user_study_logs/|Generated|.DS_Store|watchmake' ."
MAKE_ARGS = ARGV.size == 0 ? ["html"] : ARGV
MAKE_COMMAND = "cd src; make #{MAKE_ARGS.join(" ")}"
DO_LINT = false
IO.popen(FSWATCH_COMMAND) do |fswatch|
puts "Will run `#{MAKE_COMMAND}` on file changes noticed by"
puts FSWATCH_COMMAND
changed_files = ""
loop do
changed_files = fswatch.readpartial(1_000_000) if changed_files == ""
loop do
sleep(0.1 + 0.1 * Math.log(changed_files.lines.size, 10)) # File changes might still be coming (e.g. git checkout)
break unless more_changed_files = (fswatch.read_nonblock(1_000_000) rescue nil)
changed_files << more_changed_files
end
puts changed_files
puts MAKE_COMMAND
system MAKE_COMMAND
if DO_LINT
begin
changed_files = ""
# Only lint if no files changed while building and build was a success.
changed_files = fswatch.read_nonblock(1_000_000) if $?.success?
rescue
system "cd src; make lint"
end
end
end
end