module OroGen
Constants
- Generation
- OROGEN_LIB_DIR
- VERSION
Public Class Methods
beautify_loading_errors(filename) { || ... }
click to toggle source
# File lib/orogen/base.rb, line 66 def self.beautify_loading_errors(filename) yield rescue Exception => e # Two options: # * the first line of the backtrace is the orogen file # => change it into a ConfigError. If, in addition, this is a # NoMethodError then change it into a statement error # * the second line of the backtrace is in the orogen file # => most likely a bad argument, transform it into a ConfigError # too # * all other cases are reported as internal errors file_pattern = /#{Regexp.quote(File.basename(filename))}/ if e.backtrace.first =~ file_pattern if e.kind_of?(NoMethodError) || e.kind_of?(NameError) e.message =~ /undefined (?:local variable or )?method `([^']+)'/ method_name = $1 raise Generation::ConfigError, "unknown statement '#{method_name}'", e.backtrace else raise Generation::ConfigError, e.message, e.backtrace end elsif (e.backtrace[1] =~ file_pattern) || e.kind_of?(ArgumentError) raise Generation::ConfigError, e.message, e.backtrace end raise end
check_for_stray_dots(filename, name, args)
click to toggle source
Check for the case when there is an superfluous dot at the end of a task statement
# File lib/orogen/check_for_stray_dots.rb, line 4 def self.check_for_stray_dots(filename, name, args) # Building the regular expression to # match on the method name and arguments regexp_expression = "#{name}.*" args.each do |element| regexp_expression << "#{element}.*" end regexp = Regexp.new(regexp_expression) # Check the spec to locate the error in case # of stray dots File.open(filename) do |file| begin line_counter = 0 previous_non_empty_line_number = 0 previous_non_empty_line = nil while true line = file.readline line_counter += 1 if regexp.match(line) if previous_non_empty_line =~ /\.$/ raise ArgumentError, "stray dot in statement: #{previous_non_empty_line.strip} (line #{previous_non_empty_line_number})" end end if line =~ /.+/ previous_non_empty_line = line previous_non_empty_line_number = line_counter end end rescue EOFError end end end
each_orogen_plugin_dir() { |p| ... }
click to toggle source
# File lib/orogen/plugins.rb, line 6 def self.each_orogen_plugin_dir each_orogen_plugin_path do |p| if File.directory?(p) yield(p) end end end
each_orogen_plugin_file(type) { |path| ... }
click to toggle source
# File lib/orogen/plugins.rb, line 14 def self.each_orogen_plugin_file(type) each_orogen_plugin_path do |path| if File.file?(path) yield(path) else Dir.glob(File.join(path, type, '*.rb')).each do |file| yield(file) end end end end
each_orogen_plugin_path(&block)
click to toggle source
# File lib/orogen/plugins.rb, line 2 def self.each_orogen_plugin_path(&block) (ENV['OROGEN_PLUGIN_PATH'] || "").split(':').each(&block) end
load_orogen_plugin(*path)
click to toggle source
# File lib/orogen/plugins.rb, line 26 def self.load_orogen_plugin(*path) original_load_path = $LOAD_PATH.dup each_orogen_plugin_dir do |dir| $LOAD_PATH << dir end path = File.join(*path) if File.extname(path) != ".rb" path = "#{path}.rb" end each_orogen_plugin_dir do |dir| path = File.join(dir, path) if File.file?(path) info "loading plugin #{path}" require path return end end raise ArgumentError, "cannot load plugin #{path}: not found in #{ENV['OROGEN_PLUGIN_PATH']}" ensure if original_load_path $LOAD_PATH.clear $LOAD_PATH.concat(original_load_path) end end
load_orogen_plugins(*type)
click to toggle source
# File lib/orogen/plugins.rb, line 54 def self.load_orogen_plugins(*type) original_load_path = $LOAD_PATH.dup type = File.join(*type) each_orogen_plugin_dir do |dir| $LOAD_PATH << dir end each_orogen_plugin_file(type) do |file| info "loading plugin #{file}" begin require file rescue Exception => e warn "could not load plugin #{file}: #{e.message}" e.backtrace.each do |line| warn " #{line}" end end end ensure if original_load_path $LOAD_PATH.clear $LOAD_PATH.concat(original_load_path) end end
orocos_target()
click to toggle source
# File lib/orogen/base.rb, line 120 def self.orocos_target user_target = ENV['OROCOS_TARGET'] if @orocos_target @orocos_target.dup elsif user_target && !user_target.empty? user_target else 'gnulinux' end end
orocos_target=(target)
click to toggle source
# File lib/orogen/base.rb, line 115 def self.orocos_target=(target) @orocos_target = target.to_s end
registry_of(typekit_name)
click to toggle source
Load a separate typelib registry containing the types defined by the given oroGen project
# File lib/orogen/plugins.rb, line 80 def self.registry_of(typekit_name) registry = Typelib::Registry.new typekit_pkg = Utilrb::PkgConfig.new("#{typekit_name}-typekit-#{Gen::RTT_CPP.orocos_target}") tlb = typekit_pkg.type_registry if tlb registry.import(tlb) end registry end
unqualified_cxx_type(type_name)
click to toggle source
Returns the unqualified version of type_name
# File lib/orogen/base.rb, line 108 def self.unqualified_cxx_type(type_name) type_name. gsub(/(^|[^\w])const($|[^\w])/, ''). gsub(/&/, ''). strip end
validate_toplevel_type(type)
click to toggle source
# File lib/orogen/base.rb, line 101 def self.validate_toplevel_type(type) if type < Typelib::ArrayType raise Generation::ConfigError, "array types can be used only in a structure" end end
verify_valid_identifier(name)
click to toggle source
# File lib/orogen/base.rb, line 92 def self.verify_valid_identifier(name) name = name.to_s if name.respond_to?(:to_sym) name = name.to_str if name !~ /^[a-zA-Z0-9_:][a-zA-Z0-9_:]*$/ raise ArgumentError, "task name '#{name}' invalid: it can contain only alphanumeric characters and '_', and cannot start with a number" end name end
warn_deprecated(method_name, msg)
click to toggle source
# File lib/orogen/warn_deprecated.rb, line 2 def self.warn_deprecated(method_name, msg) OroGen.warn "#{method_name} is deprecated: #{msg}" end