Skip to content

Commit

Permalink
windows support
Browse files Browse the repository at this point in the history
  • Loading branch information
ddollar committed Jan 23, 2012
1 parent 4ad49cb commit f60c4cb
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 12 deletions.
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ source "http://rubygems.org"

gemspec

platform :mingw do
gem "win32console", "~> 1.3.0"
end

platform :jruby do
gem "posix-spawn", "~> 0.3.6"
end
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ GEM
rubyzip (0.9.4)
term-ansicolor (1.0.7)
thor (0.14.6)
win32console (1.3.0-x86-mingw32)
xml-simple (1.0.15)

PLATFORMS
Expand All @@ -66,3 +67,4 @@ DEPENDENCIES
rr (~> 1.0.2)
rspec (~> 2.0)
rubyzip
win32console (~> 1.3.0)
14 changes: 14 additions & 0 deletions dist/mingw32.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
file pkg("foreman-#{version}-mingw32.gem") => distribution_files do |t|
sh "env PLATFORM=mingw32 gem build foreman.gemspec"
sh "mv foreman-#{version}-mingw32.gem #{t.name}"
end

task "mingw32:build" => pkg("foreman-#{version}-mingw32.gem")

task "mingw32:clean" do
clean pkg("foreman-#{version}-mingw32.gem")
end

task "mingw32:release" => "mingw32:build" do |t|
sh "parka push -f #{pkg("foreman-#{version}-mingw32.gem")}"
end
5 changes: 5 additions & 0 deletions foreman.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@ Gem::Specification.new do |gem|
gem.add_dependency "posix-spawn", "~> 0.3.6"
gem.platform = Gem::Platform.new("java")
end

if ENV["PLATFORM"] == "mingw32"
gem.add_dependency "win32console", "~> 1.3.0"
gem.platform = Gem::Platform.new("mingw32")
end
end
9 changes: 8 additions & 1 deletion lib/foreman.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,12 @@ def self.runner
File.expand_path("../../bin/runner", __FILE__)
end

end
def self.jruby?
defined?(RUBY_PLATFORM) and RUBY_PLATFORM == "java"
end

def self.windows?
defined?(RUBY_PLATFORM) and RUBY_PLATFORM =~ /(win|w)32$/
end

end
3 changes: 2 additions & 1 deletion lib/foreman/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def terminate_gracefully

def watch_for_output
Thread.new do
require "win32console" if Foreman.windows?
begin
loop do
rs, ws = IO.select(readers.values, [], [], 1)
Expand Down Expand Up @@ -155,7 +156,7 @@ def proctitle(title)
end

def termtitle(title)
printf("\033]0;#{title}\007")
printf("\033]0;#{title}\007") unless Foreman.windows?
end

def running_processes
Expand Down
12 changes: 2 additions & 10 deletions lib/foreman/process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,14 @@ def name

private

def jruby?
defined?(RUBY_PLATFORM) and RUBY_PLATFORM == "java"
end

def windows?
defined?(RUBY_PLATFORM) and RUBY_PLATFORM =~ /(win|w)32$/
end

def fork_with_io(command, basedir)
reader, writer = IO.pipe
command = replace_command_env(command)
pid = if windows?
pid = if Foreman.windows?
Dir.chdir(basedir) do
Process.spawn command, :out => writer, :err => writer
end
elsif jruby?
elsif Foreman.jruby?
require "posix/spawn"
POSIX::Spawn.spawn(Foreman.runner, "-d", basedir, command, {
:out => writer, :err => writer
Expand Down

0 comments on commit f60c4cb

Please sign in to comment.