Top Level Namespace

Defined Under Namespace

Modules: Nokolexbor Classes: CMakeTimeout

Constant Summary collapse

MAKE =
if windows?
  # On Windows, Ruby-DevKit only has 'make'.
  find_executable('make')
else
  find_executable('gmake') || find_executable('make')
end
CWD =
File.expand_path(File.dirname(__FILE__))
LEXBOR_DIR =
File.join(CWD, '..', '..', 'vendor', 'lexbor')
EXT_DIR =
File.join(CWD, '..', '..', 'ext', 'nokolexbor')
INSTALL_DIR =
File.join(LEXBOR_DIR, 'dist')

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run_cmake(timeout, args) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'ext/nokolexbor/extconf.rb', line 79

def self.run_cmake(timeout, args)
  # Set to process group so we can kill it and its children
  pgroup = (windows? && !ENV['NOKOLEXBOR_CROSS_COMPILE']) ? :new_pgroup : :pgroup
  pid = Process.spawn("cmake #{args}", pgroup => true)

  Timeout.timeout(timeout) do
    Process.waitpid(pid)
  end

rescue Timeout::Error
  # Kill it, #detach is essentially a background wait, since we don't actually
  # care about waiting for it now
  Process.kill(-9, pid)
  Process.detach(pid)
  raise CMakeTimeout.new("cmake has exceeded its timeout of #{timeout}s")
end

Instance Method Details

#apply_patch(patch_file, chdir) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
# File 'ext/nokolexbor/extconf.rb', line 97

def apply_patch(patch_file, chdir)
  case
  when which('git')
    # By --work-tree=. git-apply uses the current directory as
    # the project root and will not search upwards for .git.
    Process.waitpid(Process.spawn("git --git-dir=. --work-tree=. apply #{patch_file}", chdir: chdir))
  when which('patch')
    Process.waitpid(Process.spawn("patch -p1 -i #{patch_file}", chdir: chdir))
  else
    raise "Failed to complete patch task; patch(1) or git(1) is required."
  end
end

#sys(cmd) ⇒ Object



67
68
69
70
71
72
73
# File 'ext/nokolexbor/extconf.rb', line 67

def sys(cmd)
  puts "-- #{cmd}"
  unless ret = xsystem(cmd)
    raise "ERROR: '#{cmd}' failed"
  end
  ret
end

#which(cmd) ⇒ Object

From: stackoverflow.com/questions/2108727 Cross-platform way of finding an executable in the $PATH.

which('ruby') #=> /usr/bin/ruby


16
17
18
19
20
21
22
23
24
25
# File 'ext/nokolexbor/extconf.rb', line 16

def which(cmd)
  exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
    exts.each { |ext|
      exe = File.join(path, "#{cmd}#{ext}")
      return exe if File.executable? exe
    }
  end
  return nil
end

#windows?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'ext/nokolexbor/extconf.rb', line 8

def windows?
  RbConfig::CONFIG["target_os"].match?(/mingw|mswin/)
end