123456789_123456789_123456789_123456789_123456789_

Class: Bazel::Runfiles::ManifestBased

Relationships & Source Files
Inherits: Object
Defined in: rb/lib/bazel/runfiles.rb

Overview

Resolves paths by looking them up in a runfiles MANIFEST file.

Class Method Summary

Instance Method Summary

Constructor Details

.new(manifest_path) ⇒ ManifestBased

[ GitHub ]

  
# File 'rb/lib/bazel/runfiles.rb', line 68

def initialize(manifest_path)
  @entries = parse_manifest(manifest_path)
end

Instance Method Details

#parse_entry(line) (private)

[ GitHub ]

  
# File 'rb/lib/bazel/runfiles.rb', line 103

def parse_entry(line)
  escaped = line.delete_prefix!(' ')
  key, _, value = line.partition(' ')
  return [key, value] unless escaped

  [unescape(key), unescape(value)]
end

#parse_manifest(path) (private)

[ GitHub ]

  
# File 'rb/lib/bazel/runfiles.rb', line 88

def parse_manifest(path)
  entries = {}
  return entries unless File.exist?(path)

  File.foreach(path) do |line|
    line.chomp!
    next if line.empty?

    key, value = parse_entry(line)
    entries[key] = value
  end

  entries
end

#rlocation(path)

[ GitHub ]

  
# File 'rb/lib/bazel/runfiles.rb', line 72

def rlocation(path)
  return @entries[path] if @entries.key?(path)

  prefix = File.dirname(path)
  while prefix != '.' && prefix != '/'
    base = @entries[prefix]
    return "#{base}#{path[prefix.length..]}" if base && !base.empty?

    prefix = File.dirname(prefix)
  end

  nil
end

#unescape(str) (private)

[ GitHub ]

  
# File 'rb/lib/bazel/runfiles.rb', line 111

def unescape(str)
  str.gsub(/\\[snb]/, '\s' => ' ', '\n' => "\n", '\b' => '\\')
end