This repository has been archived by the owner on Mar 3, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 428
/
capybara_webkit_builder.rb
106 lines (89 loc) · 1.98 KB
/
capybara_webkit_builder.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
require 'etc'
require "fileutils"
require "rbconfig"
require "shellwords"
module CapybaraWebkitBuilder
extend self
SUCCESS_STATUS = 0
COMMAND_NOT_FOUND_STATUS = 127
def make_bin
ENV['MAKE'] || 'make'
end
def qmake_bin
ENV['QMAKE'] || default_qmake_binary
end
def default_qmake_binary
case RbConfig::CONFIG['host_os']
when /freebsd/
"qmake-qt4"
when /openbsd/
"qmake-qt5"
else
"qmake"
end
end
def sh(command)
system(command)
success = $?.exitstatus == SUCCESS_STATUS
if $?.exitstatus == COMMAND_NOT_FOUND_STATUS
puts "Command '#{command}' not available"
elsif !success
puts "Command '#{command}' failed"
end
success
end
def makefile(*configs)
configs += default_configs
configs = configs.map { |config| config.shellescape}.join(" ")
sh("#{qmake_bin} #{configs}")
end
def qmake
make "qmake"
end
def path_to_binary
if Gem.win_platform?
"src/debug/webkit_server.exe"
else
"src/webkit_server"
end
end
def build
make or return false
FileUtils.mkdir("bin") unless File.directory?("bin")
FileUtils.cp(path_to_binary, "bin", :preserve => true)
end
def clean
File.open("Makefile", "w") do |file|
file.print "all:\n\t@echo ok\ninstall:\n\t@echo ok"
end
end
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
def build_all
makefile &&
qmake &&
build &&
clean
end
def make(target = "")
job_count = Etc.respond_to?(:nprocessors) ? Etc.nprocessors : 1
env_hide('CDPATH') { sh("#{make_bin} #{target} --jobs=#{job_count}") }
end
def env_hide(name)
@stored_env ||= {}
@stored_env[name] = ENV.delete(name)
yield
ensure
ENV[name] = @stored_env[name]
end
end