Module: Node::Compiler::Utils

Defined in:
lib/node/compiler/utils.rb

Class Method Summary collapse

Class Method Details

.chdir(path) ⇒ Object



23
24
25
26
27
# File 'lib/node/compiler/utils.rb', line 23

def chdir(path)
  STDERR.puts "-> cd #{path}"
  Dir.chdir(path) { yield }
  STDERR.puts "-> cd #{Dir.pwd}"
end

.inject_memfs(source, target) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/node/compiler/utils.rb', line 41

def inject_memfs(source, target)
  copy_dir = File.expand_path("./lib#{MEMFS}", target)
  if File.exist?(copy_dir)
    STDERR.puts "-> FileUtils.remove_entry_secure(#{copy_dir})"
    FileUtils.remove_entry_secure(copy_dir)
  end
  STDERR.puts "-> FileUtils.cp_r(#{source}, #{copy_dir})"
  FileUtils.cp_r(source, copy_dir)
  manifest = File.expand_path('./enclose_io_manifest.txt', target)
  File.open(manifest, "w") do |f|
    Dir["#{copy_dir}/**/*"].each do |fullpath|
      next unless File.file?(fullpath)
      if 0 == File.size(fullpath) && Gem.win_platform?
        # Fix VC++ Error C2466
        # TODO: what about empty file semantics?
        File.open(fullpath, 'w') { |f| f.puts ' ' }
      end
      entry = "lib#{fullpath[(fullpath.index MEMFS)..-1]}"
      f.puts entry
    end
  end
  return copy_dir
end

.prepare_tmpdir(tmpdir) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/node/compiler/utils.rb', line 29

def prepare_tmpdir(tmpdir)
  STDERR.puts "-> FileUtils.mkdir_p(#{tmpdir})"
  FileUtils.mkdir_p(tmpdir)
  Dir[::Node::Compiler::VENDOR_DIR + '/*'].each do |dirpath|
    target = File.join(tmpdir, File.basename(dirpath))
    unless Dir.exist?(target)
      STDERR.puts "-> FileUtils.cp_r(#{dirpath}, #{target})"
      FileUtils.cp_r(dirpath, target)
    end
  end
end

.run(*args) ⇒ Object

Raises:



16
17
18
19
20
21
# File 'lib/node/compiler/utils.rb', line 16

def run(*args)
  STDERR.puts "-> Running #{args}"
  pid = spawn(*args)
  pid, status = Process.wait2(pid)
  raise Error, "Failed running #{args}" unless status.success?
end