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



72
73
74
75
76
77
# File 'lib/capybara_webkit_builder.rb', line 72

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



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

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

#cleanObject



79
80
81
82
83
# File 'lib/capybara_webkit_builder.rb', line 79

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

#default_qmake_binaryObject



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

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

#make_binObject



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

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

#makefile(config = '') ⇒ Object



55
56
57
# File 'lib/capybara_webkit_builder.rb', line 55

def makefile(config = '')
  sh("#{qmake_bin} -spec #{spec} #{config}")
end

#os_specObject



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

def os_spec
  case RbConfig::CONFIG['host_os']
  when /linux/
    "linux-g++"
  when /freebsd/
    "freebsd-g++"
  when /mingw32/
    "win32-g++"
  else
    "macx-g++"
  end
end

#path_to_binaryObject



63
64
65
66
67
68
69
70
# File 'lib/capybara_webkit_builder.rb', line 63

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

#qmakeObject



59
60
61
# File 'lib/capybara_webkit_builder.rb', line 59

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

#qmake_binObject



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

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

#sh(command) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/capybara_webkit_builder.rb', line 44

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

#specObject



18
19
20
# File 'lib/capybara_webkit_builder.rb', line 18

def spec
  ENV['SPEC'] || os_spec
end