Skip to content

Instantly share code, notes, and snippets.

@Fonsan
Created March 7, 2011 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fonsan/858504 to your computer and use it in GitHub Desktop.
Save Fonsan/858504 to your computer and use it in GitHub Desktop.
#include <CoreServices/CoreServices.h>
static void callback(ConstFSEventStreamRef streamRef,
void *clientCallBackInfo,
size_t numEvents,
void *eventPaths,
const FSEventStreamEventFlags eventFlags[],
const FSEventStreamEventId eventIds[]) {
exit(0);
}
static int sleep_until_change(const char * path){
// Create event stream
CFStringRef pathToWatch = CFStringCreateWithCString(kCFAllocatorDefault, path, kCFStringEncodingUTF8);
CFArrayRef pathsToWatch = CFArrayCreate(NULL, (const void **)&pathToWatch, 1, NULL);
void *callbackInfo = NULL;
FSEventStreamRef stream;
CFAbsoluteTime latency = 1.0;
stream = FSEventStreamCreate(
kCFAllocatorDefault,
callback,
callbackInfo,
pathsToWatch,
kFSEventStreamEventIdSinceNow,
latency,
kFSEventStreamCreateFlagNone
);
// Add stream to run loop
FSEventStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
FSEventStreamStart(stream);
CFRunLoopRun();
// Exit
return 2;
}
`CFLAGS='-isysroot /Developer/SDKs/MacOSX#{SDK_VERSION}.sdk -mmacosx-version-min=#{SDK_VERSION}' /usr/bin/gcc -c fsevent_sleep.c -o "#{GEM_ROOT}/bin/fsevent_sleep.so"`
module Autotest::FSEvent
GEM_PATH = File.expand_path(File.join(File.dirname(__FILE__), '..', '..')) unless defined?(GEM_PATH)
extend FFI::Library
ffi_lib "/Users/fonsan/Projects/autotest-fsevent/bin/fsevent_sleep.so"
##
# Use FSEvent if possible
# Add waiting hook to prevent fallback to polling after ignored files have changed
Autotest.add_hook :initialize do
if Uname.sysname == 'Darwin' && Uname.release.to_i >= 9
class ::Autotest
remove_method :wait_for_changes
def wait_for_changes
hook :waiting
begin
`cd '#{Dir.pwd}'; #{File.join(GEM_PATH, 'bin', 'fsevent_sleep')} . 2>&1`
Kernel.sleep self.sleep
end until find_files_to_test
end
end
else
puts
puts "autotest-fsevent: platform #{Uname.sysname} #{Uname.release} is not supported"
end
end
end
/Users/fonsan/.rvm/gems/ruby-1.9.2-p180@autotest-fsevent/gems/ffi-1.0.6/lib/ffi/library.rb:75:in `block in ffi_lib': Could not open library '/Users/fonsan/Projects/autotest-fsevent/bin/fsevent_sleep.so': dlopen(/Users/fonsan/Projects/autotest-fsevent/bin/fsevent_sleep.so, 5): no suitable image found. Did find: (LoadError)
/Users/fonsan/Projects/autotest-fsevent/bin/fsevent_sleep.so: file too short
from /Users/fonsan/.rvm/gems/ruby-1.9.2-p180@autotest-fsevent/gems/ffi-1.0.6/lib/ffi/library.rb:54:in `map'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment