2011-04-15 17:19:26 -04:00
|
|
|
require "fileutils"
|
2011-10-21 15:55:08 -04:00
|
|
|
require "rbconfig"
|
2014-12-15 19:50:53 -05:00
|
|
|
require "shellwords"
|
2011-04-15 17:19:26 -04:00
|
|
|
|
|
|
|
module CapybaraWebkitBuilder
|
|
|
|
extend self
|
|
|
|
|
2012-05-25 11:40:11 -04:00
|
|
|
SUCCESS_STATUS = 0
|
|
|
|
COMMAND_NOT_FOUND_STATUS = 127
|
|
|
|
|
2011-07-25 09:43:05 -04:00
|
|
|
def make_bin
|
2012-01-27 10:26:05 -05:00
|
|
|
ENV['MAKE'] || 'make'
|
2011-07-25 09:43:05 -04:00
|
|
|
end
|
|
|
|
|
2012-01-27 10:26:05 -05:00
|
|
|
def qmake_bin
|
2012-09-05 18:33:26 -04:00
|
|
|
ENV['QMAKE'] || default_qmake_binary
|
2012-01-27 10:26:05 -05:00
|
|
|
end
|
|
|
|
|
2012-09-05 18:33:26 -04:00
|
|
|
def default_qmake_binary
|
|
|
|
case RbConfig::CONFIG['host_os']
|
|
|
|
when /freebsd/
|
|
|
|
"qmake-qt4"
|
2015-03-26 13:33:28 -04:00
|
|
|
when /openbsd/
|
|
|
|
"qmake-qt5"
|
2012-09-05 18:33:26 -04:00
|
|
|
else
|
|
|
|
"qmake"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-05-08 10:39:08 -04:00
|
|
|
def sh(command)
|
|
|
|
system(command)
|
2012-05-25 11:40:11 -04:00
|
|
|
success = $?.exitstatus == SUCCESS_STATUS
|
|
|
|
if $?.exitstatus == COMMAND_NOT_FOUND_STATUS
|
|
|
|
puts "Command '#{command}' not available"
|
2012-05-08 10:39:08 -04:00
|
|
|
elsif !success
|
|
|
|
puts "Command '#{command}' failed"
|
|
|
|
end
|
|
|
|
success
|
|
|
|
end
|
|
|
|
|
2014-12-15 19:50:53 -05:00
|
|
|
def makefile(*configs)
|
|
|
|
configs += default_configs
|
|
|
|
configs = configs.map { |config| config.shellescape}.join(" ")
|
2015-03-26 13:33:28 -04:00
|
|
|
sh("#{qmake_bin} #{configs}")
|
2012-01-27 10:26:05 -05:00
|
|
|
end
|
|
|
|
|
2011-04-15 17:19:26 -04:00
|
|
|
def qmake
|
2016-09-16 16:49:33 -04:00
|
|
|
make "qmake"
|
2011-04-15 17:19:26 -04:00
|
|
|
end
|
|
|
|
|
2011-10-06 11:07:20 -04:00
|
|
|
def path_to_binary
|
|
|
|
case RUBY_PLATFORM
|
|
|
|
when /mingw32/
|
|
|
|
"src/debug/webkit_server.exe"
|
|
|
|
else
|
|
|
|
"src/webkit_server"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-04-15 17:19:26 -04:00
|
|
|
def build
|
2016-09-16 16:49:33 -04:00
|
|
|
make or return false
|
2011-04-15 17:19:26 -04:00
|
|
|
|
|
|
|
FileUtils.mkdir("bin") unless File.directory?("bin")
|
2011-10-06 11:07:20 -04:00
|
|
|
FileUtils.cp(path_to_binary, "bin", :preserve => true)
|
2011-04-15 17:19:26 -04:00
|
|
|
end
|
|
|
|
|
2012-03-08 11:53:59 -05:00
|
|
|
def clean
|
|
|
|
File.open("Makefile", "w") do |file|
|
|
|
|
file.print "all:\n\t@echo ok\ninstall:\n\t@echo ok"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-12-15 19:50:53 -05:00
|
|
|
def default_configs
|
|
|
|
configs = []
|
|
|
|
libpath = ENV["CAPYBARA_WEBKIT_LIBS"]
|
|
|
|
cppflags = ENV["CAPYBARA_WEBKIT_INCLUDE_PATH"]
|
|
|
|
if libpath
|
|
|
|
configs << "LIBS += #{libpath}"
|
|
|
|
end
|
|
|
|
if cppflags
|
|
|
|
configs << "INCLUDEPATH += #{cppflags}"
|
|
|
|
end
|
|
|
|
configs
|
|
|
|
end
|
|
|
|
|
2011-04-15 17:19:26 -04:00
|
|
|
def build_all
|
2011-05-05 17:45:44 -04:00
|
|
|
makefile &&
|
|
|
|
qmake &&
|
2012-03-08 11:53:59 -05:00
|
|
|
build &&
|
|
|
|
clean
|
2011-04-15 17:19:26 -04:00
|
|
|
end
|
2016-09-16 16:49:33 -04:00
|
|
|
|
|
|
|
def make(target = "")
|
|
|
|
env_hide("CDPATH") { sh("#{make_bin} #{target}") }
|
|
|
|
end
|
|
|
|
|
|
|
|
def env_hide(name)
|
|
|
|
@stored_env ||= {}
|
|
|
|
@stored_env[name] = ENV.delete(name)
|
|
|
|
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
ENV[name] = @stored_env[name]
|
|
|
|
end
|
2011-04-15 17:19:26 -04:00
|
|
|
end
|