From 827c3fc054d182a8d40cadb11b01a95e673126ee Mon Sep 17 00:00:00 2001 From: Joshua Clayton Date: Fri, 15 Apr 2011 17:19:26 -0400 Subject: [PATCH] Move code that compiles Webkit into separate file to support Ruby 1.9.2 Closes #15 --- Gemfile | 1 - Gemfile.lock | 1 - Rakefile | 134 +++++++++++++++------------------ capybara-webkit.gemspec | 1 - extconf.rb | 4 +- lib/capybara_webkit_builder.rb | 31 ++++++++ 6 files changed, 93 insertions(+), 79 deletions(-) create mode 100644 lib/capybara_webkit_builder.rb diff --git a/Gemfile b/Gemfile index 910534b..ed17047 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,4 @@ source "http://rubygems.org" -gem "rake" gem "rspec", :require => false gem "capybara" gem "sinatra", :require => false diff --git a/Gemfile.lock b/Gemfile.lock index edc4f57..7a3085e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -50,6 +50,5 @@ PLATFORMS DEPENDENCIES capybara - rake rspec sinatra diff --git a/Rakefile b/Rakefile index 9ecf76d..540b9b0 100644 --- a/Rakefile +++ b/Rakefile @@ -1,91 +1,77 @@ -require 'fileutils' - -unless ENV["BUILD"] - require 'rubygems' - require 'bundler/setup' - require 'rspec/core/rake_task' - require 'rake/gempackagetask' -end +require 'rubygems' +require 'bundler/setup' +require 'rspec/core/rake_task' +require 'rake/gempackagetask' +require 'capybara_webkit_builder' desc "Generate a Makefile using qmake" file 'Makefile' do - sh("qmake -spec macx-g++") + CapybaraWebkitBuilder.makefile end desc "Regenerate dependencies using qmake" task :qmake => 'Makefile' do - sh("make qmake") + CapybaraWebkitBuilder.qmake end desc "Build the webkit server" task :build => :qmake do - sh("make") - - FileUtils.mkdir("bin") unless File.directory?("bin") - - if File.exist?("src/webkit_server.app") - FileUtils.cp("src/webkit_server.app/Contents/MacOS/webkit_server", "bin", :preserve => true) - else - FileUtils.cp("src/webkit_server", "bin", :preserve => true) - end + CapybaraWebkitBuilder.build end file 'bin/webkit_server' => :build -unless ENV["BUILD"] - RSpec::Core::RakeTask.new do |t| - t.pattern = "spec/**/*_spec.rb" - t.rspec_opts = "--format progress" - end - - desc "Default: build and run all specs" - task :default => [:build, :spec] - - eval("$specification = begin; #{IO.read('capybara-webkit.gemspec')}; end") - Rake::GemPackageTask.new($specification) do |package| - package.need_zip = true - package.need_tar = true - end - - gem_file = "pkg/#{$specification.name}-#{$specification.version}.gem" - - desc "Build and install the latest gem" - task :install => :gem do - sh("gem install --local #{gem_file}") - end - - desc "Build and release the latest gem" - task :release => :gem do - sh("gem push #{gem_file}") - end - - desc "Generate a new command called NAME" - task :generate_command do - name = ENV['NAME'] or raise "Provide a name with NAME=" - - header = "src/#{name}.h" - source = "src/#{name}.cpp" - - %w(h cpp).each do |extension| - File.open("templates/Command.#{extension}", "r") do |source_file| - contents = source_file.read - contents.gsub!("NAME", name) - File.open("src/#{name}.#{extension}", "w") do |target_file| - target_file.write(contents) - end - end - end - - Dir.glob("src/*.pro").each do |project_file_name| - project = IO.read(project_file_name) - project.gsub!(/^(HEADERS = .*)/, "\\1 #{name}.h") - project.gsub!(/^(SOURCES = .*)/, "\\1 #{name}.cpp") - File.open(project_file_name, "w") { |file| file.write(project) } - end - - File.open("src/find_command.h", "a") do |file| - file.write("CHECK_COMMAND(#{name})") - end - end +RSpec::Core::RakeTask.new do |t| + t.pattern = "spec/**/*_spec.rb" + t.rspec_opts = "--format progress" end +desc "Default: build and run all specs" +task :default => [:build, :spec] + +eval("$specification = begin; #{IO.read('capybara-webkit.gemspec')}; end") +Rake::GemPackageTask.new($specification) do |package| + package.need_zip = true + package.need_tar = true +end + +gem_file = "pkg/#{$specification.name}-#{$specification.version}.gem" + +desc "Build and install the latest gem" +task :install => :gem do + sh("gem install --local #{gem_file}") +end + +desc "Build and release the latest gem" +task :release => :gem do + sh("gem push #{gem_file}") +end + +desc "Generate a new command called NAME" +task :generate_command do + name = ENV['NAME'] or raise "Provide a name with NAME=" + + header = "src/#{name}.h" + source = "src/#{name}.cpp" + + %w(h cpp).each do |extension| + File.open("templates/Command.#{extension}", "r") do |source_file| + contents = source_file.read + contents.gsub!("NAME", name) + File.open("src/#{name}.#{extension}", "w") do |target_file| + target_file.write(contents) + end + end + end + + Dir.glob("src/*.pro").each do |project_file_name| + project = IO.read(project_file_name) + project.gsub!(/^(HEADERS = .*)/, "\\1 #{name}.h") + project.gsub!(/^(SOURCES = .*)/, "\\1 #{name}.cpp") + File.open(project_file_name, "w") { |file| file.write(project) } + end + + File.open("src/find_command.h", "a") do |file| + file.write("CHECK_COMMAND(#{name})") + end +end diff --git a/capybara-webkit.gemspec b/capybara-webkit.gemspec index b40c98f..ff80006 100644 --- a/capybara-webkit.gemspec +++ b/capybara-webkit.gemspec @@ -10,7 +10,6 @@ Gem::Specification.new do |s| s.rubygems_version = "1.3.5" s.summary = "Headless Webkit driver for Capybara" s.add_runtime_dependency "capybara", "~> 0.4.1" - s.add_runtime_dependency "rake" s.extensions = "extconf.rb" end diff --git a/extconf.rb b/extconf.rb index 87d822e..6d76fac 100644 --- a/extconf.rb +++ b/extconf.rb @@ -1,2 +1,2 @@ -system("rake build BUILD=true") - +require File.join(File.expand_path(File.dirname(__FILE__)), "lib", "capybara_webkit_builder") +CapybaraWebkitBuilder.build_all diff --git a/lib/capybara_webkit_builder.rb b/lib/capybara_webkit_builder.rb new file mode 100644 index 0000000..4247fe1 --- /dev/null +++ b/lib/capybara_webkit_builder.rb @@ -0,0 +1,31 @@ +require "fileutils" + +module CapybaraWebkitBuilder + extend self + + def makefile + system("qmake -spec macx-g++") + end + + def qmake + system("make qmake") + end + + def build + system("make") + + FileUtils.mkdir("bin") unless File.directory?("bin") + + if File.exist?("src/webkit_server.app") + FileUtils.cp("src/webkit_server.app/Contents/MacOS/webkit_server", "bin", :preserve => true) + else + FileUtils.cp("src/webkit_server", "bin", :preserve => true) + end + end + + def build_all + makefile + qmake + build + end +end