childprocess 0.5.9 → 0.6.0

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 (47) hide show
  1. checksums.yaml +4 -4
  2. data/.document +6 -6
  3. data/.gitignore +25 -25
  4. data/.rspec +1 -1
  5. data/.travis.yml +20 -18
  6. data/CHANGELOG.md +8 -0
  7. data/Gemfile +11 -4
  8. data/LICENSE +20 -20
  9. data/README.md +178 -178
  10. data/Rakefile +61 -61
  11. data/childprocess.gemspec +30 -29
  12. data/lib/childprocess.rb +184 -177
  13. data/lib/childprocess/abstract_io.rb +36 -36
  14. data/lib/childprocess/abstract_process.rb +187 -187
  15. data/lib/childprocess/errors.rb +26 -26
  16. data/lib/childprocess/jruby.rb +56 -56
  17. data/lib/childprocess/jruby/io.rb +16 -16
  18. data/lib/childprocess/jruby/process.rb +159 -159
  19. data/lib/childprocess/jruby/pump.rb +52 -52
  20. data/lib/childprocess/tools/generator.rb +145 -145
  21. data/lib/childprocess/unix.rb +9 -9
  22. data/lib/childprocess/unix/fork_exec_process.rb +70 -70
  23. data/lib/childprocess/unix/io.rb +21 -21
  24. data/lib/childprocess/unix/lib.rb +186 -186
  25. data/lib/childprocess/unix/platform/i386-linux.rb +12 -12
  26. data/lib/childprocess/unix/platform/i386-solaris.rb +11 -11
  27. data/lib/childprocess/unix/platform/x86_64-linux.rb +12 -12
  28. data/lib/childprocess/unix/platform/x86_64-macosx.rb +11 -11
  29. data/lib/childprocess/unix/posix_spawn_process.rb +134 -134
  30. data/lib/childprocess/unix/process.rb +89 -89
  31. data/lib/childprocess/version.rb +3 -3
  32. data/lib/childprocess/windows.rb +33 -33
  33. data/lib/childprocess/windows/handle.rb +91 -91
  34. data/lib/childprocess/windows/io.rb +25 -25
  35. data/lib/childprocess/windows/lib.rb +415 -415
  36. data/lib/childprocess/windows/process.rb +129 -129
  37. data/lib/childprocess/windows/process_builder.rb +174 -174
  38. data/lib/childprocess/windows/structs.rb +148 -148
  39. data/spec/abstract_io_spec.rb +12 -12
  40. data/spec/childprocess_spec.rb +291 -256
  41. data/spec/io_spec.rb +228 -228
  42. data/spec/jruby_spec.rb +24 -24
  43. data/spec/pid_behavior.rb +12 -12
  44. data/spec/spec_helper.rb +253 -253
  45. data/spec/unix_spec.rb +57 -57
  46. data/spec/windows_spec.rb +23 -23
  47. metadata +47 -45
data/Rakefile CHANGED
@@ -1,61 +1,61 @@
1
- require 'rubygems'
2
- require 'rake'
3
- require 'tmpdir'
4
-
5
- require 'bundler'
6
- Bundler::GemHelper.install_tasks
7
-
8
- include Rake::DSL if defined?(::Rake::DSL)
9
-
10
- require 'rspec/core/rake_task'
11
- RSpec::Core::RakeTask.new(:spec) do |spec|
12
- spec.ruby_opts = "-I lib:spec -w"
13
- spec.pattern = 'spec/**/*_spec.rb'
14
- end
15
-
16
- desc 'Run specs for rcov'
17
- RSpec::Core::RakeTask.new(:rcov) do |spec|
18
- spec.ruby_opts = "-I lib:spec"
19
- spec.pattern = 'spec/**/*_spec.rb'
20
- spec.rcov = true
21
- spec.rcov_opts = %w[--exclude spec,ruby-debug,/Library/Ruby,.gem --include lib/childprocess]
22
- end
23
-
24
- task :default => :spec
25
-
26
- begin
27
- require 'yard'
28
- YARD::Rake::YardocTask.new
29
- rescue LoadError
30
- task :yardoc do
31
- abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
32
- end
33
- end
34
-
35
- task :clean do
36
- rm_rf "pkg"
37
- rm_rf "childprocess.jar"
38
- end
39
-
40
- desc 'Create jar to bundle in selenium-webdriver'
41
- task :jar => [:clean, :build] do
42
- tmpdir = Dir.mktmpdir("childprocess-jar")
43
- gem_to_package = Dir['pkg/*.gem'].first
44
- gem_name = File.basename(gem_to_package, ".gem")
45
- p :gem_to_package => gem_to_package, :gem_name => gem_name
46
-
47
- sh "gem install -i #{tmpdir} #{gem_to_package} --ignore-dependencies --no-rdoc --no-ri"
48
- sh "jar cf childprocess.jar -C #{tmpdir}/gems/#{gem_name}/lib ."
49
- sh "jar tf childprocess.jar"
50
- end
51
-
52
- task :env do
53
- $:.unshift File.expand_path("../lib", __FILE__)
54
- require 'childprocess'
55
- end
56
-
57
- desc 'Calculate size of posix_spawn structs for the current platform'
58
- task :generate => :env do
59
- require 'childprocess/tools/generator'
60
- ChildProcess::Tools::Generator.generate
61
- end
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'tmpdir'
4
+
5
+ require 'bundler'
6
+ Bundler::GemHelper.install_tasks
7
+
8
+ include Rake::DSL if defined?(::Rake::DSL)
9
+
10
+ require 'rspec/core/rake_task'
11
+ RSpec::Core::RakeTask.new(:spec) do |spec|
12
+ spec.ruby_opts = "-I lib:spec -w"
13
+ spec.pattern = 'spec/**/*_spec.rb'
14
+ end
15
+
16
+ desc 'Run specs for rcov'
17
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
18
+ spec.ruby_opts = "-I lib:spec"
19
+ spec.pattern = 'spec/**/*_spec.rb'
20
+ spec.rcov = true
21
+ spec.rcov_opts = %w[--exclude spec,ruby-debug,/Library/Ruby,.gem --include lib/childprocess]
22
+ end
23
+
24
+ task :default => :spec
25
+
26
+ begin
27
+ require 'yard'
28
+ YARD::Rake::YardocTask.new
29
+ rescue LoadError
30
+ task :yardoc do
31
+ abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
32
+ end
33
+ end
34
+
35
+ task :clean do
36
+ rm_rf "pkg"
37
+ rm_rf "childprocess.jar"
38
+ end
39
+
40
+ desc 'Create jar to bundle in selenium-webdriver'
41
+ task :jar => [:clean, :build] do
42
+ tmpdir = Dir.mktmpdir("childprocess-jar")
43
+ gem_to_package = Dir['pkg/*.gem'].first
44
+ gem_name = File.basename(gem_to_package, ".gem")
45
+ p :gem_to_package => gem_to_package, :gem_name => gem_name
46
+
47
+ sh "gem install -i #{tmpdir} #{gem_to_package} --ignore-dependencies --no-rdoc --no-ri"
48
+ sh "jar cf childprocess.jar -C #{tmpdir}/gems/#{gem_name}/lib ."
49
+ sh "jar tf childprocess.jar"
50
+ end
51
+
52
+ task :env do
53
+ $:.unshift File.expand_path("../lib", __FILE__)
54
+ require 'childprocess'
55
+ end
56
+
57
+ desc 'Calculate size of posix_spawn structs for the current platform'
58
+ task :generate => :env do
59
+ require 'childprocess/tools/generator'
60
+ ChildProcess::Tools::Generator.generate
61
+ end
@@ -1,29 +1,30 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "childprocess/version"
4
-
5
- Gem::Specification.new do |s|
6
- s.name = "childprocess"
7
- s.version = ChildProcess::VERSION
8
- s.platform = Gem::Platform::RUBY
9
- s.authors = ["Jari Bakken"]
10
- s.email = ["jari.bakken@gmail.com"]
11
- s.homepage = "http://github.com/jarib/childprocess"
12
- s.summary = %q{This gem aims at being a simple and reliable solution for controlling external programs running in the background on any Ruby / OS combination.}
13
- s.description = %q{This gem aims at being a simple and reliable solution for controlling external programs running in the background on any Ruby / OS combination.}
14
-
15
- s.rubyforge_project = "childprocess"
16
- s.license = 'MIT'
17
-
18
- s.files = `git ls-files`.split("\n")
19
- s.test_files = `git ls-files -- spec/*`.split("\n")
20
- s.require_paths = ["lib"]
21
-
22
- s.add_development_dependency "rspec", "~> 3.0.0"
23
- s.add_development_dependency "yard", ">= 0"
24
- s.add_development_dependency "rake", "~> 0.9.2"
25
- s.add_development_dependency 'coveralls'
26
- s.add_runtime_dependency "ffi", "~> 1.0", ">= 1.0.11"
27
- end
28
-
29
-
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "childprocess/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "childprocess"
7
+ s.version = ChildProcess::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Jari Bakken", "Eric Kessler"]
10
+ s.email = ["morrow748@gmail.com"]
11
+ s.homepage = "http://github.com/enkessler/childprocess"
12
+ s.summary = %q{A simple and reliable solution for controlling external programs running in the background on any Ruby / OS combination.}
13
+ s.description = %q{This gem aims at being a simple and reliable solution for controlling external programs running in the background on any Ruby / OS combination.}
14
+
15
+ s.rubyforge_project = "childprocess"
16
+ s.license = 'MIT'
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- spec/*`.split("\n")
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_runtime_dependency "ffi", "~> 1.0", ">= 1.0.11"
23
+
24
+ s.add_development_dependency "rspec", "~> 3.0"
25
+ s.add_development_dependency "yard", "~> 0.0"
26
+ s.add_runtime_dependency 'rake', '< 12.0'
27
+ s.add_development_dependency 'coveralls', '< 1.0'
28
+ end
29
+
30
+
@@ -1,177 +1,184 @@
1
- require 'childprocess/errors'
2
- require 'childprocess/abstract_process'
3
- require 'childprocess/abstract_io'
4
- require "fcntl"
5
-
6
- module ChildProcess
7
-
8
- @posix_spawn = false
9
-
10
- class << self
11
- def new(*args)
12
- case os
13
- when :macosx, :linux, :solaris, :bsd, :cygwin, :aix
14
- if posix_spawn?
15
- Unix::PosixSpawnProcess.new(args)
16
- elsif jruby?
17
- JRuby::Process.new(args)
18
- else
19
- Unix::ForkExecProcess.new(args)
20
- end
21
- when :windows
22
- Windows::Process.new(args)
23
- else
24
- raise Error, "unsupported platform #{platform_name.inspect}"
25
- end
26
- end
27
- alias_method :build, :new
28
-
29
- def platform
30
- if RUBY_PLATFORM == "java"
31
- :jruby
32
- elsif defined?(RUBY_ENGINE) && RUBY_ENGINE == "ironruby"
33
- :ironruby
34
- else
35
- os
36
- end
37
- end
38
-
39
- def platform_name
40
- @platform_name ||= "#{arch}-#{os}"
41
- end
42
-
43
- def unix?
44
- !windows?
45
- end
46
-
47
- def linux?
48
- os == :linux
49
- end
50
-
51
- def jruby?
52
- platform == :jruby
53
- end
54
-
55
- def windows?
56
- os == :windows
57
- end
58
-
59
- def posix_spawn?
60
- enabled = @posix_spawn || %w[1 true].include?(ENV['CHILDPROCESS_POSIX_SPAWN'])
61
- return false unless enabled
62
-
63
- require 'ffi'
64
- begin
65
- require "childprocess/unix/platform/#{ChildProcess.platform_name}"
66
- rescue LoadError
67
- raise ChildProcess::MissingPlatformError
68
- end
69
-
70
- require "childprocess/unix/lib"
71
- require 'childprocess/unix/posix_spawn_process'
72
-
73
- true
74
- rescue ChildProcess::MissingPlatformError => ex
75
- warn_once ex.message
76
- false
77
- end
78
-
79
- #
80
- # Set this to true to enable experimental use of posix_spawn.
81
- #
82
-
83
- def posix_spawn=(bool)
84
- @posix_spawn = bool
85
- end
86
-
87
- def os
88
- @os ||= (
89
- require "rbconfig"
90
- host_os = RbConfig::CONFIG['host_os'].downcase
91
-
92
- case host_os
93
- when /linux/
94
- :linux
95
- when /darwin|mac os/
96
- :macosx
97
- when /mswin|msys|mingw32/
98
- :windows
99
- when /cygwin/
100
- :cygwin
101
- when /solaris|sunos/
102
- :solaris
103
- when /bsd/
104
- :bsd
105
- when /aix/
106
- :aix
107
- else
108
- raise Error, "unknown os: #{host_os.inspect}"
109
- end
110
- )
111
- end
112
-
113
- def arch
114
- @arch ||= (
115
- host_cpu = RbConfig::CONFIG['host_cpu'].downcase
116
- case host_cpu
117
- when /i[3456]86/
118
- # Darwin always reports i686, even when running in 64bit mod
119
- if os == :macosx && 0xfee1deadbeef.is_a?(Fixnum)
120
- "x86_64"
121
- else
122
- "i386"
123
- end
124
- when /amd64|x86_64/
125
- "x86_64"
126
- when /ppc|powerpc/
127
- "powerpc"
128
- else
129
- host_cpu
130
- end
131
- )
132
- end
133
-
134
- #
135
- # By default, a child process will inherit open file descriptors from the
136
- # parent process. This helper provides a cross-platform way of making sure
137
- # that doesn't happen for the given file/io.
138
- #
139
-
140
- def close_on_exec(file)
141
- if file.respond_to?(:close_on_exec=)
142
- file.close_on_exec = true
143
- elsif file.respond_to?(:fcntl) && defined?(Fcntl::FD_CLOEXEC)
144
- file.fcntl Fcntl::F_SETFD, Fcntl::FD_CLOEXEC
145
-
146
- if jruby? && posix_spawn?
147
- # on JRuby, the fcntl call above apparently isn't enough when
148
- # we're launching the process through posix_spawn.
149
- fileno = JRuby.posix_fileno_for(file)
150
- Unix::Lib.fcntl fileno, Fcntl::F_SETFD, Fcntl::FD_CLOEXEC
151
- end
152
- elsif windows?
153
- Windows::Lib.dont_inherit file
154
- else
155
- raise Error, "not sure how to set close-on-exec for #{file.inspect} on #{platform_name.inspect}"
156
- end
157
- end
158
-
159
- private
160
-
161
- def warn_once(msg)
162
- @warnings ||= {}
163
-
164
- unless @warnings[msg]
165
- @warnings[msg] = true
166
- $stderr.puts msg
167
- end
168
- end
169
-
170
- end # class << self
171
- end # ChildProcess
172
-
173
- require 'jruby' if ChildProcess.jruby?
174
-
175
- require 'childprocess/unix' if ChildProcess.unix?
176
- require 'childprocess/windows' if ChildProcess.windows?
177
- require 'childprocess/jruby' if ChildProcess.jruby?
1
+ require 'childprocess/version'
2
+ require 'childprocess/errors'
3
+ require 'childprocess/abstract_process'
4
+ require 'childprocess/abstract_io'
5
+ require "fcntl"
6
+
7
+ module ChildProcess
8
+
9
+ @posix_spawn = false
10
+
11
+ class << self
12
+ def new(*args)
13
+ case os
14
+ when :macosx, :linux, :solaris, :bsd, :cygwin, :aix
15
+ if posix_spawn?
16
+ Unix::PosixSpawnProcess.new(args)
17
+ elsif jruby?
18
+ JRuby::Process.new(args)
19
+ else
20
+ Unix::ForkExecProcess.new(args)
21
+ end
22
+ when :windows
23
+ Windows::Process.new(args)
24
+ else
25
+ raise Error, "unsupported platform #{platform_name.inspect}"
26
+ end
27
+ end
28
+ alias_method :build, :new
29
+
30
+ def platform
31
+ if RUBY_PLATFORM == "java"
32
+ :jruby
33
+ elsif defined?(RUBY_ENGINE) && RUBY_ENGINE == "ironruby"
34
+ :ironruby
35
+ else
36
+ os
37
+ end
38
+ end
39
+
40
+ def platform_name
41
+ @platform_name ||= "#{arch}-#{os}"
42
+ end
43
+
44
+ def unix?
45
+ !windows?
46
+ end
47
+
48
+ def linux?
49
+ os == :linux
50
+ end
51
+
52
+ def jruby?
53
+ platform == :jruby
54
+ end
55
+
56
+ def windows?
57
+ os == :windows
58
+ end
59
+
60
+ def posix_spawn?
61
+ enabled = @posix_spawn || %w[1 true].include?(ENV['CHILDPROCESS_POSIX_SPAWN'])
62
+ return false unless enabled
63
+
64
+ require 'ffi'
65
+ begin
66
+ require "childprocess/unix/platform/#{ChildProcess.platform_name}"
67
+ rescue LoadError
68
+ raise ChildProcess::MissingPlatformError
69
+ end
70
+
71
+ require "childprocess/unix/lib"
72
+ require 'childprocess/unix/posix_spawn_process'
73
+
74
+ true
75
+ rescue ChildProcess::MissingPlatformError => ex
76
+ warn_once ex.message
77
+ false
78
+ end
79
+
80
+ #
81
+ # Set this to true to enable experimental use of posix_spawn.
82
+ #
83
+
84
+ def posix_spawn=(bool)
85
+ @posix_spawn = bool
86
+ end
87
+
88
+ def os
89
+ @os ||= (
90
+ require "rbconfig"
91
+ host_os = RbConfig::CONFIG['host_os'].downcase
92
+
93
+ case host_os
94
+ when /linux/
95
+ :linux
96
+ when /darwin|mac os/
97
+ :macosx
98
+ when /mswin|msys|mingw32/
99
+ :windows
100
+ when /cygwin/
101
+ :cygwin
102
+ when /solaris|sunos/
103
+ :solaris
104
+ when /bsd/
105
+ :bsd
106
+ when /aix/
107
+ :aix
108
+ else
109
+ raise Error, "unknown os: #{host_os.inspect}"
110
+ end
111
+ )
112
+ end
113
+
114
+ def arch
115
+ @arch ||= (
116
+ host_cpu = RbConfig::CONFIG['host_cpu'].downcase
117
+ case host_cpu
118
+ when /i[3456]86/
119
+
120
+ # Ruby 2.4 unifies Bignum and Fixnum into Integer. Also, I've heard that Darwin no
121
+ # longer has this issue, so on newer Ruby/Darwin combos this check shouldn't be
122
+ # needed anyway. Leaving it here for older combinations, however.
123
+
124
+ # Check for Ruby older version of Ruby
125
+ if (RUBY_VERSION =~ /^[123]\./) && (os == :macosx) && (0xfee1deadbeef.is_a?(Fixnum))
126
+ # Darwin always reports i686, even when running in 64bit mod
127
+ "x86_64"
128
+ else
129
+ "i386"
130
+ end
131
+ when /amd64|x86_64/
132
+ "x86_64"
133
+ when /ppc|powerpc/
134
+ "powerpc"
135
+ else
136
+ host_cpu
137
+ end
138
+ )
139
+ end
140
+
141
+ #
142
+ # By default, a child process will inherit open file descriptors from the
143
+ # parent process. This helper provides a cross-platform way of making sure
144
+ # that doesn't happen for the given file/io.
145
+ #
146
+
147
+ def close_on_exec(file)
148
+ if file.respond_to?(:close_on_exec=)
149
+ file.close_on_exec = true
150
+ elsif file.respond_to?(:fcntl) && defined?(Fcntl::FD_CLOEXEC)
151
+ file.fcntl Fcntl::F_SETFD, Fcntl::FD_CLOEXEC
152
+
153
+ if jruby? && posix_spawn?
154
+ # on JRuby, the fcntl call above apparently isn't enough when
155
+ # we're launching the process through posix_spawn.
156
+ fileno = JRuby.posix_fileno_for(file)
157
+ Unix::Lib.fcntl fileno, Fcntl::F_SETFD, Fcntl::FD_CLOEXEC
158
+ end
159
+ elsif windows?
160
+ Windows::Lib.dont_inherit file
161
+ else
162
+ raise Error, "not sure how to set close-on-exec for #{file.inspect} on #{platform_name.inspect}"
163
+ end
164
+ end
165
+
166
+ private
167
+
168
+ def warn_once(msg)
169
+ @warnings ||= {}
170
+
171
+ unless @warnings[msg]
172
+ @warnings[msg] = true
173
+ $stderr.puts msg
174
+ end
175
+ end
176
+
177
+ end # class << self
178
+ end # ChildProcess
179
+
180
+ require 'jruby' if ChildProcess.jruby?
181
+
182
+ require 'childprocess/unix' if ChildProcess.unix?
183
+ require 'childprocess/windows' if ChildProcess.windows?
184
+ require 'childprocess/jruby' if ChildProcess.jruby?