-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathautobuild.rb
executable file
·90 lines (65 loc) · 1.76 KB
/
autobuild.rb
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env ruby
# If you have Leopard, you can run ./autobuild.rb, and any time you save a file in etc or spec
# it will try to build it, and if it builds, run the specs
require 'open3'
require 'osx/foundation'
OSX.require_framework '/System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework'
include OSX
def make
stdin, stdout, stderr = Open3.popen3("make")
return true if stderr.eof?
puts "MAKE FAILED!"
while(out = stdout.gets)
puts out
end
while(out = stderr.gets)
puts out
end
end
def make_install
stdin, stdout, stderr = Open3.popen3("make install")
return true if stderr.eof?
puts "MAKE INSTALL FAILED!"
while(out = stdout.gets)
puts out
end
while(out = stderr.gets)
puts out
end
end
def run_specs
puts "="*80
system("spec -c -fs spec/")
puts "="*80
end
def build_extension
if make && make_install
run_specs
end
end
# http://rails.aizatto.com/2007/12/11/automatically-restart-scriptserver-for-easier-plugin-development-with-fsevents/
callback = proc do |stream, ctx, numEvents, paths, marks, eventIDs|
paths.regard_as('*')
rpaths = []
length = Dir.pwd.length + 1
numEvents.times { |i| rpaths << paths[i][length..-1] }
next if rpaths.select { |path| path =~ /ext|spec/ }.empty?
build_extension
end
stream = FSEventStreamCreate(KCFAllocatorDefault, callback, nil, [Dir.pwd], KFSEventStreamEventIdSinceNow, 1.0, 0)
unless stream
puts "Failed to create stream"
exit
end
FSEventStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(), KCFRunLoopDefaultMode)
unless FSEventStreamStart(stream)
puts "Failed to start stream"
exit
end
begin
CFRunLoopRun()
rescue Interrupt
FSEventStreamStop(stream)
FSEventStreamInvalidate(stream)
FSEventStreamRelease(stream)
end