autotest-inotify 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/LICENSE +20 -0
  2. data/README.rdoc +63 -0
  3. data/lib/autotest/inotify.rb +94 -0
  4. metadata +77 -0
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Eric A. Wollesen
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,63 @@
1
+ = Autotest Inotify
2
+
3
+ * Author: Eric A. Wollesen (http://kill-0.com)
4
+ * Homepage: http://kill-0.com/projects/autotest-inotify
5
+
6
+ == DESCRIPTION:
7
+
8
+ Autotest relies on filesystem polling to detect modifications in source code
9
+ files. In other words: The filesytem is constantly being traversed which
10
+ causes quite some load on both the CPU and the harddrive. This is not healthy
11
+ for your machine and if you are working on a portable computer, it will drain
12
+ your battery. Linux offers libinotify which is a very efficient way to have
13
+ the operating system monitor file alterations. This gem teaches autotest to
14
+ use libinotify and therefore be nice to your machine.
15
+
16
+ == REQUIREMENTS:
17
+
18
+ * Linux
19
+ * rb-inotify
20
+ * autotest >= 4.2.4
21
+
22
+ == INSTALL:
23
+
24
+ First install the gem:
25
+
26
+ sudo gem install autotest-inotify
27
+
28
+ Then add the following line *after all other requires* in your ~/.autotest
29
+ file:
30
+
31
+ require 'autotest/inotify'
32
+
33
+ == THANK YOU:
34
+
35
+ Inspiration for this gem came from work done by Alban Peignier's[1], and Sven
36
+ Schwyn[2]
37
+
38
+ 1. http://blog.tryphon.org/alban/archives/2007/10/26/inotify-support-for-autotest/
39
+ 2. http://www.bitcetera.com/en/techblog/2009/05/27/mac-friendly-autotest/
40
+
41
+ == LICENSE:
42
+
43
+ (The MIT License)
44
+
45
+ Copyright (c) 2009 Eric A. Wollesen
46
+
47
+ Permission is hereby granted, free of charge, to any person obtaining
48
+ a copy of this software and associated documentation files (the
49
+ 'Software'), to deal in the Software without restriction, including
50
+ without limitation the rights to use, copy, modify, merge, publish,
51
+ distribute, sublicense, and/or sell copies of the Software, and to
52
+ permit persons to whom the Software is furnished to do so, subject to
53
+ the following conditions:
54
+
55
+ The above copyright notice and this permission notice shall be
56
+ included in all copies or substantial portions of the Software.
57
+
58
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
59
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
60
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
61
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
62
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
63
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
@@ -0,0 +1,94 @@
1
+ # Extend autotest with inotify goodness
2
+
3
+ require "rubygems"
4
+ require "autotest"
5
+ require "rbconfig"
6
+ require "rb-inotify"
7
+
8
+ Autotest.add_hook :initialize do
9
+ include Autotest::Inotify
10
+ setup_inotify_if_running_linux
11
+ end
12
+
13
+ ##
14
+ # Autotest::Inofity
15
+ #
16
+ # == FEATURES:
17
+ # * Use Linux's inotify instead of filesystem polling
18
+ #
19
+ # == SYNOPSIS:
20
+ # Add the following to your ~/.autotest file:
21
+ # require "autotest/inotify"
22
+ module Autotest::Inotify
23
+
24
+ private
25
+
26
+ def setup_inotify_if_running_linux
27
+ if running_linux?
28
+ override_autotest_methods
29
+ end
30
+ end
31
+
32
+ def running_linux?
33
+ /linux/i === RbConfig::CONFIG["host_os"]
34
+ end
35
+
36
+ def override_autotest_methods
37
+ ::Autotest.class_eval do
38
+ remove_method :find_files_to_test
39
+ remove_method :wait_for_changes
40
+
41
+ def wait_for_changes
42
+ @changed_files = {}
43
+ hook :waiting
44
+ @notifier.process
45
+ end
46
+
47
+ def find_files_to_test(files=nil)
48
+ if first_time_run?
49
+ setup_inotify
50
+ select_all_tests
51
+ else
52
+ p @changed_files if $v
53
+ hook :updated, @changed_files
54
+ select_tests_for_changed_files
55
+ end
56
+ return Time.now
57
+ end
58
+ end
59
+ end
60
+
61
+ def first_time_run?
62
+ self.last_mtime.to_i.zero?
63
+ end
64
+
65
+ def setup_inotify
66
+ @notifier = INotify::Notifier.new
67
+ self.find_files.keys.each do |filename|
68
+ @notifier.watch(filename, :modify) do |event|
69
+ handle_file_event(event)
70
+ end
71
+ end
72
+ end
73
+
74
+ def handle_file_event(event)
75
+ @changed_files[event.absolute_name] = Time.now
76
+ end
77
+
78
+ def select_all_tests
79
+ map_files_to_tests_for(find_files).each do |filename|
80
+ self.files_to_test[filename]
81
+ end
82
+ end
83
+
84
+ def map_files_to_tests_for(files)
85
+ files.map {|filename, mtime| test_files_for(filename)}.flatten.uniq
86
+ end
87
+
88
+ def select_tests_for_changed_files
89
+ map_files_to_tests_for(@changed_files).each do |filename|
90
+ self.files_to_test[filename]
91
+ end
92
+ end
93
+
94
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: autotest-inotify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Eric Wollesen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-11 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: autotest
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 4.2.4
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rb-inotify
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: Autotest relies on filesystem polling to detect modifications in source code files. This is expensive for the CPU, harddrive and battery - and unnecesary on Linux with libinotify installed. This gem teaches autotest how to use libinotify.
36
+ email: ericw@kill-0.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - lib/autotest/inotify.rb
46
+ - LICENSE
47
+ - README.rdoc
48
+ has_rdoc: true
49
+ homepage: http://kill-0.com/projects/autotest-inotify
50
+ licenses: []
51
+
52
+ post_install_message:
53
+ rdoc_options:
54
+ - --charset=UTF-8
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ version:
69
+ requirements: []
70
+
71
+ rubyforge_project:
72
+ rubygems_version: 1.3.5
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: Use libinotify (on Linux) instead of filesystem polling.
76
+ test_files: []
77
+