Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Compiling on Windows #188

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
@@ -1,5 +1,5 @@
*.swp *.swp
bin/webkit_server bin/webkit_server*
*.swo *.swo
*~ *~
*.o *.o
Expand All @@ -12,6 +12,8 @@ moc_*.cpp
.bundle .bundle
pkg pkg
src/webkit_server src/webkit_server
src/webkit_server.exe
.DS_Store .DS_Store
tmp tmp
.rvmrc .rvmrc
src/debug
3 changes: 3 additions & 0 deletions Gemfile.lock
Expand Up @@ -21,11 +21,13 @@ GEM
ffi (~> 1.0.6) ffi (~> 1.0.6)
diff-lcs (1.1.2) diff-lcs (1.1.2)
ffi (1.0.9) ffi (1.0.9)
ffi (1.0.9-x86-mingw32)
json_pure (1.6.1) json_pure (1.6.1)
mime-types (1.16) mime-types (1.16)
mini_magick (3.2.1) mini_magick (3.2.1)
subexec (~> 0.0.4) subexec (~> 0.0.4)
nokogiri (1.5.0) nokogiri (1.5.0)
nokogiri (1.5.0-x86-mingw32)
rack (1.3.2) rack (1.3.2)
rack-test (0.6.1) rack-test (0.6.1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you downgrade rake?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh well, I had the Rake::DSL not found problem on my machine with 0.9.2.
I then forgot to fix that before commit, now I restored 0.9.2 and merged with master.

rack (>= 1.0) rack (>= 1.0)
Expand Down Expand Up @@ -54,6 +56,7 @@ GEM


PLATFORMS PLATFORMS
ruby ruby
x86-mingw32


DEPENDENCIES DEPENDENCIES
appraisal (~> 0.4.0) appraisal (~> 0.4.0)
Expand Down
29 changes: 19 additions & 10 deletions lib/capybara/driver/webkit/browser.rb
Expand Up @@ -2,16 +2,17 @@
require 'thread' require 'thread'
require 'capybara/util/timeout' require 'capybara/util/timeout'
require 'json' require 'json'
require 'rbconfig'


class Capybara::Driver::Webkit class Capybara::Driver::Webkit
class Browser class Browser
attr :server_port attr :server_port


def initialize(options = {}) def initialize(options = {})
@socket_class = options[:socket_class] || TCPSocket @socket_class = options[:socket_class] || TCPSocket
@stdout = options.has_key?(:stdout) ? @stdout = options.has_key?(:stdout) ?
options[:stdout] : options[:stdout] :
$stdout $stdout
@ignore_ssl_errors = options[:ignore_ssl_errors] @ignore_ssl_errors = options[:ignore_ssl_errors]
start_server start_server
connect connect
Expand Down Expand Up @@ -113,7 +114,7 @@ def clear_cookies
end end


def get_cookies def get_cookies
command("GetCookies").lines.map{ |line| line.strip }.select{ |line| !line.empty? } command("GetCookies").lines.map { |line| line.strip }.select { |line| !line.empty? }
end end


def set_proxy(options = {}) def set_proxy(options = {})
Expand Down Expand Up @@ -147,11 +148,19 @@ def register_shutdown_hook
@owner_pid = Process.pid @owner_pid = Process.pid
at_exit do at_exit do
if Process.pid == @owner_pid if Process.pid == @owner_pid
Process.kill("INT", @pid) kill_process(@pid)
end end
end end
end end


def kill_process(pid)
if RbConfig::CONFIG['host_os'] =~ /mingw32/
Process.kill(9, pid)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for our edification, why 9 for mingw32 instead of the 2 (INT) we use elsewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment below

else
Process.kill("INT", pid)
end
end

def server_pipe_and_pid(server_path) def server_pipe_and_pid(server_path)
cmdline = [server_path] cmdline = [server_path]
cmdline << "--ignore-ssl-errors" if @ignore_ssl_errors cmdline << "--ignore-ssl-errors" if @ignore_ssl_errors
Expand Down Expand Up @@ -207,7 +216,7 @@ def check


if result.nil? if result.nil?
raise WebkitNoResponseError, "No response received from the server." raise WebkitNoResponseError, "No response received from the server."
elsif result != 'ok' elsif result != 'ok'
raise WebkitInvalidResponseError, read_response raise WebkitInvalidResponseError, read_response
end end


Expand All @@ -223,10 +232,10 @@ def read_response


def default_proxy_options def default_proxy_options
{ {
:host => "localhost", :host => "localhost",
:port => "0", :port => "0",
:user => "", :user => "",
:pass => "" :pass => ""
} }
end end
end end
Expand Down
43 changes: 33 additions & 10 deletions lib/capybara_webkit_builder.rb
Expand Up @@ -4,38 +4,61 @@
module CapybaraWebkitBuilder module CapybaraWebkitBuilder
extend self extend self


def has_binary?(binary)
case RbConfig::CONFIG['host_os']
when /mingw32/
system("#{binary} --version")
else
system("which #{make}")
end
end

def make_bin def make_bin
make_binaries = ['gmake', 'make'] make_binaries = ['gmake', 'make']
make_binaries.detect { |make| system("which #{make}") } make_binaries.detect { |make| has_binary?(make) }
end end


def makefile def qmake_bin
qmake_binaries = ['qmake', 'qmake-qt4'] qmake_binaries = ['qmake', 'qmake-qt4']
qmake = qmake_binaries.detect { |qmake| system("which #{qmake}") } qmake_binaries.detect { |qmake| has_binary?(qmake) }
end

def makefile
case RbConfig::CONFIG['host_os'] case RbConfig::CONFIG['host_os']
when /linux/ when /linux/
system("#{qmake} -spec linux-g++") system("#{qmake_bin} -spec linux-g++")
when /freebsd/ when /freebsd/
system("#{qmake} -spec freebsd-g++") system("#{qmake_bin} -spec freebsd-g++")
when /mingw32/
system("#{qmake_bin} -spec win32-g++")
else else
system("#{qmake} -spec macx-g++") system("#{qmake_bin} -spec macx-g++")
end end
end end


def qmake def qmake
system("#{make_bin} qmake") system("#{make_bin} qmake")
end end


def path_to_binary
case RbConfig::CONFIG['host_os']
when /mingw32/
'src/debug/webkit_server.exe'
else
'src/webkit_server'
end
end

def build def build
system(make_bin) or return false system(make_bin) or return false


FileUtils.mkdir("bin") unless File.directory?("bin") FileUtils.mkdir("bin") unless File.directory?("bin")
FileUtils.cp("src/webkit_server", "bin", :preserve => true) FileUtils.cp(path_to_binary, "bin", :preserve => true)
end end


def build_all def build_all
makefile && makefile &&
qmake && qmake &&
build build
end end
end end
5 changes: 3 additions & 2 deletions spec/browser_spec.rb
Expand Up @@ -81,7 +81,8 @@
browser_ignore_ssl_err.visit "https://#{@host}:#{@port}/" browser_ignore_ssl_err.visit "https://#{@host}:#{@port}/"
end end
end end
describe "forking" do
describe "forking", :skip_on_windows => true do
it "only shuts down the server from the main process" do it "only shuts down the server from the main process" do
browser.reset! browser.reset!
pid = fork {} pid = fork {}
Expand All @@ -95,7 +96,7 @@
@host = '127.0.0.1' @host = '127.0.0.1'
@user = 'user' @user = 'user'
@pass = 'secret' @pass = 'secret'
@url = "http://example.org/" @url = "http://example.org/"


@server = TCPServer.new(@host, 0) @server = TCPServer.new(@host, 0)
@port = @server.addr[1] @port = @server.addr[1]
Expand Down
11 changes: 8 additions & 3 deletions spec/spec_helper.rb
@@ -1,5 +1,6 @@
require 'rspec' require 'rspec'
require 'rspec/autorun' require 'rspec/autorun'
require 'rbconfig'


PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')).freeze PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')).freeze


Expand All @@ -10,12 +11,16 @@
spec_dir = nil spec_dir = nil
$:.detect do |dir| $:.detect do |dir|
if File.exists? File.join(dir, "capybara.rb") if File.exists? File.join(dir, "capybara.rb")
spec_dir = File.expand_path(File.join(dir,"..","spec")) spec_dir = File.expand_path(File.join(dir, "..", "spec"))
$:.unshift( spec_dir ) $:.unshift(spec_dir)
end end
end end


require File.join(spec_dir,"spec_helper") RSpec.configure do |c|
c.filter_run_excluding :skip_on_windows => !(RbConfig::CONFIG['host_os'] =~ /mingw32/).nil?
end

require File.join(spec_dir, "spec_helper")


require 'capybara/driver/webkit/browser' require 'capybara/driver/webkit/browser'
$webkit_browser = Capybara::Driver::Webkit::Browser.new(:socket_class => TCPSocket, :stdout => nil) $webkit_browser = Capybara::Driver::Webkit::Browser.new(:socket_class => TCPSocket, :stdout => nil)
Expand Down