module OroGen::Gen::RTT_CPP
Constants
- AUTOMATIC_AREA_NAME
- Attribute
- ConfigError
- ConfigurationObject
- DynamicInputPort
- DynamicOutputPort
- InputPort
- OROGEN_LIB_DIR
- Operation
- OutputPort
- Port
- Property
- TaskContext
Attributes
The set of files generated so far, as a set of absolute paths
The set of templates already loaded as a path => ERB object hash
Multiple type info objects can be grouped in a single file to reduce the overhead, at compilation time, of reading the preprocessed file
This controls the size of the grouping
Public Class Methods
Returns the C++ code which changes the current namespace from
old to new. indent_size is the count
of indent spaces between namespaces.
# File lib/orogen/gen/base.rb, line 23 def self.adapt_namespace(old, new, indent_size = 4) old = old.split('/').delete_if { |v| v.empty? } new = new.split('/').delete_if { |v| v.empty? } indent = old.size * indent_size result = "" while !old.empty? && old.first == new.first old.shift new.shift end while !old.empty? indent -= indent_size result << " " * indent + "}\n" old.shift end while !new.empty? result << "#{" " * indent}namespace #{new.first} {\n" indent += indent_size new.shift end result end
Returns the directory where Orogen's lib part sits (i.e. where autobuild.rb and autobuild/ are)
# File lib/orogen/gen/base.rb, line 6 def self.base_dir File.expand_path(File.join('..', '..'), File.dirname(__FILE__)) end
# File lib/orogen/gen/templates.rb, line 187 def self.clean FileUtils.rm_rf Generation::AUTOMATIC_AREA_NAME FileUtils.rm_rf "build" FileUtils.rm_rf "templates" end
Removes from the given path all files that have not been generated
# File lib/orogen/gen/templates.rb, line 149 def self.cleanup_dir(*path) dir_path = File.expand_path(File.join(*path)) Find.find(dir_path) do |file| if File.directory?(file) && File.directory?(File.join(file, "CMakeFiles")) # This looks like a build directory. Ignore Find.prune elsif File.file?(file) && !File.symlink?(file) && !generated_files.include?(file) info " removing #{file}" FileUtils.rm_f file end end end
# File lib/orogen/gen/base.rb, line 96 def self.cmake_pkgconfig_link(context, target, depspec) depspec.inject([]) do |result, s| if s.in_context?(context, 'link') result << "target_link_libraries(#{target} ${#{s.var_name}_LIBRARIES})" end result end.join("\n") + "\n" end
# File lib/orogen/gen/base.rb, line 105 def self.cmake_pkgconfig_link_corba(target, depspec) cmake_pkgconfig_link('corba', target, depspec) end
# File lib/orogen/gen/base.rb, line 108 def self.cmake_pkgconfig_link_noncorba(target, depspec) cmake_pkgconfig_link('core', target, depspec) end
# File lib/orogen/gen/base.rb, line 82 def self.cmake_pkgconfig_require(depspec, context = 'core') depspec.inject([]) do |result, s| result << "orogen_pkg_check_modules(#{s.var_name} REQUIRED #{s.pkg_name})" if s.in_context?(context, 'include') result << "include_directories(${#{s.var_name}_INCLUDE_DIRS})" result << "add_definitions(${#{s.var_name}_CFLAGS_OTHER})" end if s.in_context?(context, 'link') result << "link_directories(${#{s.var_name}_LIBRARY_DIRS})" end result end.join("\n") + "\n" end
Helper method used to create a symbolic link. If a link already exists, it makes sure that it is up to date
# File lib/orogen/gen/typekit.rb, line 350 def self.create_or_update_symlink(source, target) if File.exists?(target) if !File.symlink?(target) raise ConfigError, "#{target} was expected to be a symbolic link, but is not" end pointed_to = File.readlink(target) if pointed_to == target return else FileUtils.rm_f target end end FileUtils.mkdir_p(File.dirname(target)) FileUtils.ln_sf(source, target) end
# File lib/orogen/gen/project.rb, line 17 def self.default_deployment_name(task_model_name) "orogen_default_#{task_model_name.gsub(/[^\w]/, '_')}" end
# File lib/orogen/gen/project.rb, line 23 def default_type_export_policy=(value) if ![:all, :used].include?(value) raise ArgumentError, "the default type export policy must be either 'all' or 'used', got '#{value}'" end @default_type_export_policy = value end
# File lib/orogen/gen/project.rb, line 13 def self.define_default_deployments=(value); @define_default_deployments = value end
# File lib/orogen/gen/project.rb, line 14 def self.define_default_deployments_enabled?; @define_default_deployments end
# File lib/orogen/gen/enable.rb, line 4 def self.enable Attribute.include AttributeGeneration Property.include PropertyGeneration Operation.include OperationGeneration Port.include PortGeneration OutputPort.include OutputPortGeneration InputPort.include InputPortGeneration TaskContext.include TaskContextGeneration end
# File lib/orogen/gen/project.rb, line 9 def self.extended_states=(value); @extended_states = value end
# File lib/orogen/gen/project.rb, line 10 def self.extended_states_enabled?; @extended_states end
Loads the template file located at template_dir/path1/path2/…/file_name and return the ERB object generated from it. template_dir is the templates/ directory located in Orocos.rb sources.
A template is only loaded once. See Generation.templates.
# File lib/orogen/gen/templates.rb, line 44 def self.load_template(*path) if template = templates[path] template else template_file = template_path(*path) templates[path] = begin ERB.new(File.read(template_file), nil, "<>", path.join('_').downcase.gsub(/[\/\.-]/, '_')) rescue Errno::ENOENT raise ArgumentError, "template #{File.join(*path)} does not exist" end templates[path].filename = template_file templates[path] end end
# File lib/orogen/gen/tasks.rb, line 4 def self.multiline_string_to_cxx(str) if str "\"#{str.split("\n").join("\\n").gsub('"', '\\"')}\"" else "\"\"" end end
# File lib/orogen/gen/project.rb, line 57 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
# File lib/orogen/gen/project.rb, line 52 def self.orocos_target=(target) @orocos_target = target.to_s end
# File lib/orogen/gen/templates.rb, line 164 def self.really_clean # List all files in templates and compare them w.r.t. the ones in # the user-side of the project. Remove those that are identical base_dir = Pathname.new('.') template_dir = Pathname.new('templates') template_dir.find do |path| next unless path.file? template_data = File.read(path.to_s) relative = path.relative_path_from(template_dir) if relative.file? user_data = File.read(relative.to_s) if user_data == template_data logger.info "removing #{relative} as it is the same than in template" FileUtils.rm_f relative.to_s end end end # Call #clean afterwards, since #clean removes the templates/ directory clean end
Render the template found at path1/path2/file_name and render it using the provided binding
# File lib/orogen/gen/templates.rb, line 65 def self.render_template(*args) binding = args.pop template = load_template(*args) debug "rendering #{File.join(*args)}" template.result(binding) rescue Exception => e raise e, "while rendering #{File.join(*args)}: #{e.message}", e.backtrace end
Save the provided data in the path1/path2/…/file_name file of the automatically-generated part of the project (i.e. under .orogen)
# File lib/orogen/gen/templates.rb, line 118 def self.save_automatic(*args) save_generated true, AUTOMATIC_AREA_NAME, *args end
Save the provided data in the path1/path2/file_name file of the user-written part of the project. It differs from ::save_user because it will happily overwrite an existing file.
# File lib/orogen/gen/templates.rb, line 128 def self.save_public_automatic(*args) save_generated true, *args end
Save the provided data in the path1/path2/file_name file of the user-written part of the project, if the said file does not exist yet
# File lib/orogen/gen/templates.rb, line 138 def self.save_user(*args) result = save_generated false, *args # Save the template in path1/path2/.../orogen/file_name args = args.dup args.unshift "templates" save_generated true, *args result end
Returns the full path for the template path1/path2/…/file_name. Templates names are the path relative to the template base directory, which is the orocos/templates directory directly in orogen sources.
Alternative, if an absolute path it passed, it will be directly returned
# File lib/orogen/gen/templates.rb, line 26 def self.template_path(*path) if Pathname.new(File.join(*path)).absolute? File.join(*path) else reldir = File.join('orogen', 'templates', *path) File.expand_path(reldir, base_dir) end end
Creates an empty file path1/path2/…/file_name
# File lib/orogen/gen/base.rb, line 14 def self.touch(*args) path = File.expand_path(File.join(*args)) FileUtils.touch path generated_files << path end