Module: CapybaraWebkitBuilder

Extended by:
CapybaraWebkitBuilder
Included in:
CapybaraWebkitBuilder
Defined in:
lib/capybara_webkit_builder.rb

Constant Summary collapse

SUCCESS_STATUS =
0
COMMAND_NOT_FOUND_STATUS =
127

Instance Method Summary collapse

Instance Method Details

#buildObject



60
61
62
63
64
65
# File 'lib/capybara_webkit_builder.rb', line 60

def build
  sh(make_bin) or return false

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

#build_allObject



86
87
88
89
90
91
# File 'lib/capybara_webkit_builder.rb', line 86

def build_all
  makefile &&
  qmake &&
  build &&
  clean
end

#cleanObject



67
68
69
70
71
# File 'lib/capybara_webkit_builder.rb', line 67

def clean
  File.open("Makefile", "w") do |file|
    file.print "all:\n\t@echo ok\ninstall:\n\t@echo ok"
  end
end

#default_configsObject



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/capybara_webkit_builder.rb', line 73

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

#default_qmake_binaryObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/capybara_webkit_builder.rb', line 19

def default_qmake_binary
  case RbConfig::CONFIG['host_os']
  when /freebsd/
    "qmake-qt4"
  when /openbsd/
    "qmake-qt5"
  else
    "qmake"
  end
end

#make_binObject



11
12
13
# File 'lib/capybara_webkit_builder.rb', line 11

def make_bin
  ENV['MAKE'] || 'make'
end

#makefile(*configs) ⇒ Object



41
42
43
44
45
# File 'lib/capybara_webkit_builder.rb', line 41

def makefile(*configs)
  configs += default_configs
  configs = configs.map { |config| config.shellescape}.join(" ")
  sh("#{qmake_bin} #{configs}")
end

#path_to_binaryObject



51
52
53
54
55
56
57
58
# File 'lib/capybara_webkit_builder.rb', line 51

def path_to_binary
  case RUBY_PLATFORM
  when /mingw32/
    "src/debug/webkit_server.exe"
  else
    "src/webkit_server"
  end
end

#qmakeObject



47
48
49
# File 'lib/capybara_webkit_builder.rb', line 47

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

#qmake_binObject



15
16
17
# File 'lib/capybara_webkit_builder.rb', line 15

def qmake_bin
  ENV['QMAKE'] || default_qmake_binary
end

#sh(command) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/capybara_webkit_builder.rb', line 30

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