class Autoproj::Ops::Loader

Attributes

file_stack[R]

@return [Array<String>] information about what is being loaded

root_dir[R]

The path w.r.t. which we should resolve relative paths

@return [String]

Public Class Methods

new(root_dir) click to toggle source
# File lib/autoproj/ops/loader.rb, line 11
def initialize(root_dir)
    @root_dir = root_dir
    @file_stack = Array.new
    @loaded_autobuild_files = Set.new
end

Public Instance Methods

current_file() click to toggle source

Returns the information about the file that is currently being loaded

The return value is [package_set, path], where package_set is the PackageSet instance and path is the path of the file w.r.t. the autoproj root directory

# File lib/autoproj/ops/loader.rb, line 52
def current_file
    unless (file = @file_stack.last)
        raise ArgumentError, "not in a #in_package_set context"
    end

    file
end
current_package_set() click to toggle source

The PackageSet object representing the package set that is currently being loaded

# File lib/autoproj/ops/loader.rb, line 62
def current_package_set
    current_file.first
end
filter_load_exception(error, package_set, path) click to toggle source
# File lib/autoproj/ops/loader.rb, line 25
def filter_load_exception(error, package_set, path)
    raise error if Autoproj.verbose

    rx_path = Regexp.quote(path)
    unless (error_line = error.backtrace.find { |l| l =~ /#{rx_path}/ })
        raise error
    end

    if (line_number = Integer(/#{rx_path}:(\d+)/.match(error_line)[1]))
        line_number = "#{line_number}:"
    end

    if package_set.local?
        raise ConfigError.new(path),
              "#{path}:#{line_number} #{error.message}", error.backtrace
    else
        raise ConfigError.new(path),
              "#{File.basename(path)}(package_set=#{package_set.name}):"\
              "#{line_number} #{error.message}", error.backtrace
    end
end
import_autobuild_file(package_set, path) click to toggle source
# File lib/autoproj/ops/loader.rb, line 97
def import_autobuild_file(package_set, path)
    return if @loaded_autobuild_files.include?(path)

    load(package_set, path)
    @loaded_autobuild_files << path
end
in_package_set(pkg_set, path) { || ... } click to toggle source
# File lib/autoproj/ops/loader.rb, line 17
def in_package_set(pkg_set, path)
    path = File.expand_path(path, root_dir) if path
    @file_stack.push([pkg_set, path])
    yield
ensure
    @file_stack.pop
end
load(pkg_set, *path) click to toggle source

Load a definition file from a package set

If any error is detected, the backtrace will be filtered so that it is easier to understand by the user. Moreover, if source is non-nil, the package set name will be mentionned.

@param [PackageSet] pkg_set @param [Array<String>] path

# File lib/autoproj/ops/loader.rb, line 74
def load(pkg_set, *path)
    path = File.join(*path)
    relative_path =
        File.expand_path(path).gsub(/^#{Regexp.quote(root_dir)}\//, "")
    in_package_set(pkg_set, relative_path) do
        Kernel.load path
    rescue Interrupt
        raise
    rescue ConfigError => e
        raise
    rescue Exception => e
        filter_load_exception(e, pkg_set, path)
    end
end
load_if_present(pkg_set, *path) click to toggle source

Load a definition file from a package set if the file is present

(see load)

# File lib/autoproj/ops/loader.rb, line 92
def load_if_present(pkg_set, *path)
    path = File.join(*path)
    load(pkg_set, *path) if File.file?(path)
end