Module: OroGen::Gen::RTT_CPP
- Extended by:
- Logger::Hierarchy
- Includes:
- TaskDeploymentGeneration
- Included in:
- SelfTest
- Defined in:
- lib/orogen.rb,
lib/orogen/gen.rb,
lib/orogen/gen/deployment.rb,
lib/orogen/gen/imports.rb,
lib/orogen/gen/project.rb,
lib/orogen/gen/tasks.rb,
lib/orogen/gen/typekit.rb,
lib/orogen/gen/base.rb,
lib/orogen/gen/test.rb,
lib/orogen/gen/enable.rb,
lib/orogen/gen/templates.rb
Defined Under Namespace
Modules: AttributeGeneration, ConfigurationObjectGeneration, InputPortGeneration, OpaqueHandling, OperationGeneration, OutputPortGeneration, PortGeneration, PropertyGeneration, RTTTypekit, SelfTest, TaskContextGeneration, TaskDeploymentGeneration Classes: BuildDependency, Deployment, ImportedProject, ImportedTypekit, OpaqueDefinition, Project, TypeSets, Typekit
Constant Summary collapse
- ConfigError =
OroGen::ConfigError
- OROGEN_LIB_DIR =
OroGen::OROGEN_LIB_DIR
- ConfigurationObject =
Spec::ConfigurationObject
- Attribute =
Spec::Attribute
- Property =
Spec::Property
- Operation =
Spec::Operation
- Port =
Spec::Port
- OutputPort =
Spec::OutputPort
- InputPort =
Spec::InputPort
- DynamicInputPort =
Spec::DynamicInputPort
- DynamicOutputPort =
Spec::DynamicInputPort
- TaskContext =
Spec::TaskContext
- AUTOMATIC_AREA_NAME =
'.orogen'
Class Attribute Summary collapse
-
.command_line_options ⇒ Object
Returns the value of attribute command_line_options.
-
.default_type_export_policy ⇒ Object
Returns the value of attribute default_type_export_policy.
-
.generated_files ⇒ Object
readonly
The set of files generated so far, as a set of absolute paths.
-
.generation_directory ⇒ Object
Returns the value of attribute generation_directory.
-
.relative_generation_directory ⇒ Object
Returns the value of attribute relative_generation_directory.
-
.templates ⇒ Object
readonly
The set of templates already loaded as a path => ERB object hash.
-
.typekit_slice ⇒ Object
Multiple type info objects can be grouped in a single file to reduce the overhead, at compilation time, of reading the preprocessed file.
-
.typekit_slice_minimum ⇒ Object
Returns the value of attribute typekit_slice_minimum.
Class Method Summary collapse
-
.adapt_namespace(old, new, indent_size = 4) ⇒ Object
Returns the C++ code which changes the current namespace from
old
tonew
. -
.base_dir ⇒ Object
Returns the directory where oroGen's lib part sits, i.e.
- .clean ⇒ Object
-
.cleanup_dir(*path) ⇒ Object
Removes from the given path all files that have not been generated.
- .cmake_pkgconfig_link(context, target, depspec) ⇒ Object
- .cmake_pkgconfig_link_corba(target, depspec) ⇒ Object
- .cmake_pkgconfig_link_noncorba(target, depspec) ⇒ Object
- .cmake_pkgconfig_require(depspec, context = 'core') ⇒ Object
-
.create_or_update_symlink(source, target) ⇒ Object
Helper method used to create a symbolic link.
- .default_deployment_name(task_model_name) ⇒ Object
- .define_default_deployments=(value) ⇒ Object
- .define_default_deployments_enabled? ⇒ Boolean
- .enable ⇒ Object
- .extended_states=(value) ⇒ Object
- .extended_states_enabled? ⇒ Boolean
-
.load_template(*path) ⇒ Object
call-seq: load_template path1, path2, …, file_name => erb object.
- .multiline_string_to_cxx(str) ⇒ Object
- .orocos_target ⇒ Object
- .orocos_target=(target) ⇒ Object
- .really_clean ⇒ Object
-
.render_template(*args) ⇒ Object
call-seq: render_template path1, path2, file_name, binding.
-
.save_automatic(*args) ⇒ Object
call-seq: save_automatic path1, path2, …, file_name, data.
-
.save_generated(overwrite, *args) ⇒ Object
:nodoc:.
-
.save_public_automatic(*args) ⇒ Object
call-seq: save_public_automatic path1, path2, …, file_name, data.
-
.save_user(*args) ⇒ Object
call-seq: save_user path1, path2, …, file_name, data.
-
.template_path(*path) ⇒ Object
call-seq: template_path(path1, path2, …, file_name).
-
.touch(*args) ⇒ Object
call-seq: touch path1, path2, …, file_name.
Methods included from TaskDeploymentGeneration
#generate_activity_setup, #method_missing, #rtt_priority, #rtt_scheduler, #to_deployer_xml
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class OroGen::Gen::RTT_CPP::TaskDeploymentGeneration
Class Attribute Details
.command_line_options ⇒ Object
Returns the value of attribute command_line_options
34 35 36 |
# File 'lib/orogen/gen/project.rb', line 34 def @command_line_options end |
.default_type_export_policy ⇒ Object
Returns the value of attribute default_type_export_policy
22 23 24 |
# File 'lib/orogen/gen/project.rb', line 22 def default_type_export_policy @default_type_export_policy end |
.generated_files ⇒ Object (readonly)
The set of files generated so far, as a set of absolute paths
76 77 78 |
# File 'lib/orogen/gen/templates.rb', line 76 def generated_files @generated_files end |
.generation_directory ⇒ Object
Returns the value of attribute generation_directory
41 42 43 |
# File 'lib/orogen/gen/project.rb', line 41 def generation_directory @generation_directory end |
.relative_generation_directory ⇒ Object
Returns the value of attribute relative_generation_directory
48 49 50 |
# File 'lib/orogen/gen/project.rb', line 48 def relative_generation_directory @relative_generation_directory end |
.templates ⇒ Object (readonly)
The set of templates already loaded as a path => ERB object hash
9 10 11 |
# File 'lib/orogen/gen/templates.rb', line 9 def templates @templates end |
.typekit_slice ⇒ Object
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
491 492 493 |
# File 'lib/orogen/gen/typekit.rb', line 491 def typekit_slice @typekit_slice end |
.typekit_slice_minimum ⇒ Object
Returns the value of attribute typekit_slice_minimum
492 493 494 |
# File 'lib/orogen/gen/typekit.rb', line 492 def typekit_slice_minimum @typekit_slice_minimum end |
Class Method Details
.adapt_namespace(old, new, indent_size = 4) ⇒ Object
Returns the C++ code which changes the current namespace from
old
to new
. indent_size
is the count
of indent spaces between namespaces.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# 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 |
.base_dir ⇒ Object
Returns the directory where oroGen's lib part sits, i.e. base_dir is defined by the directory where orogen.rb resides
6 7 8 |
# File 'lib/orogen/gen/base.rb', line 6 def self.base_dir File.(File.join('..', '..'), File.dirname(__FILE__)) end |
.clean ⇒ Object
187 188 189 190 191 |
# 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 |
.cleanup_dir(*path) ⇒ Object
Removes from the given path all files that have not been generated
149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/orogen/gen/templates.rb', line 149 def self.cleanup_dir(*path) dir_path = File.(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 |
.cmake_pkgconfig_link(context, target, depspec) ⇒ Object
96 97 98 99 100 101 102 103 |
# 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 |
.cmake_pkgconfig_link_corba(target, depspec) ⇒ Object
105 106 107 |
# File 'lib/orogen/gen/base.rb', line 105 def self.cmake_pkgconfig_link_corba(target, depspec) cmake_pkgconfig_link('corba', target, depspec) end |
.cmake_pkgconfig_link_noncorba(target, depspec) ⇒ Object
108 109 110 |
# File 'lib/orogen/gen/base.rb', line 108 def self.cmake_pkgconfig_link_noncorba(target, depspec) cmake_pkgconfig_link('core', target, depspec) end |
.cmake_pkgconfig_require(depspec, context = 'core') ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# 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 |
.create_or_update_symlink(source, target) ⇒ Object
Helper method used to create a symbolic link. If a link already exists, it makes sure that it is up to date
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
# File 'lib/orogen/gen/typekit.rb', line 351 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 |
.default_deployment_name(task_model_name) ⇒ Object
17 18 19 |
# File 'lib/orogen/gen/project.rb', line 17 def self.default_deployment_name(task_model_name) "orogen_default_#{task_model_name.gsub(/[^\w]/, '_')}" end |
.define_default_deployments=(value) ⇒ Object
13 |
# File 'lib/orogen/gen/project.rb', line 13 def self.define_default_deployments=(value); @define_default_deployments = value end |
.define_default_deployments_enabled? ⇒ Boolean
14 |
# File 'lib/orogen/gen/project.rb', line 14 def self.define_default_deployments_enabled?; @define_default_deployments end |
.enable ⇒ Object
4 5 6 7 8 9 10 11 12 |
# 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 |
.extended_states=(value) ⇒ Object
9 |
# File 'lib/orogen/gen/project.rb', line 9 def self.extended_states=(value); @extended_states = value end |
.extended_states_enabled? ⇒ Boolean
10 |
# File 'lib/orogen/gen/project.rb', line 10 def self.extended_states_enabled?; @extended_states end |
.load_template(*path) ⇒ Object
call-seq:
load_template path1, path2, ..., file_name => erb object
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.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# 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 |
.multiline_string_to_cxx(str) ⇒ Object
4 5 6 7 8 9 |
# 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 |
.orocos_target ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# 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 |
.orocos_target=(target) ⇒ Object
52 53 54 |
# File 'lib/orogen/gen/project.rb', line 52 def self.orocos_target=(target) @orocos_target = target.to_s end |
.really_clean ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# 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_template(*args) ⇒ Object
call-seq:
render_template path1, path2, file_name, binding
Render the template found at path1/path2/file_name and render it using the provided binding
65 66 67 68 69 70 71 72 |
# 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.}", e.backtrace end |
.save_automatic(*args) ⇒ Object
call-seq:
save_automatic path1, path2, ..., file_name, data
Save the provided data in the path1/path2/…/file_name file of the automatically-generated part of the project (i.e. under .orogen)
118 119 120 |
# File 'lib/orogen/gen/templates.rb', line 118 def self.save_automatic(*args) save_generated true, AUTOMATIC_AREA_NAME, *args end |
.save_generated(overwrite, *args) ⇒ Object
:nodoc:
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/orogen/gen/templates.rb', line 80 def self.save_generated(overwrite, *args) # :nodoc: if args.size < 2 raise ArgumentError, "expected at least 2 arguments, got #{args.size}" end data = args.pop file_path = File.(File.join(*args)) dir_name = File.dirname(file_path) FileUtils.mkdir_p(dir_name) generated_files << file_path if File.exists?(file_path) if File.read(file_path) != data if overwrite info " overwriting #{file_path}" else info " will not overwrite #{file_path}" return file_path end else debug " #{file_path} has not changed" return file_path end else info " creating #{file_path}" end File.open(file_path, 'w') do |io| io.write data end file_path end |
.save_public_automatic(*args) ⇒ Object
call-seq:
save_public_automatic path1, path2, ..., file_name, data
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.
128 129 130 |
# File 'lib/orogen/gen/templates.rb', line 128 def self.save_public_automatic(*args) save_generated true, *args end |
.save_user(*args) ⇒ Object
call-seq:
save_user path1, path2, ..., file_name, data
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
138 139 140 141 142 143 144 145 146 |
# 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 |
.template_path(*path) ⇒ Object
call-seq:
template_path(path1, path2, ..., file_name)
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
26 27 28 29 30 31 32 33 |
# 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.(reldir, base_dir) end end |
.touch(*args) ⇒ Object
call-seq:
touch path1, path2, ..., file_name
Creates an empty file path1/path2/…/file_name
14 15 16 17 18 |
# File 'lib/orogen/gen/base.rb', line 14 def self.touch(*args) path = File.(File.join(*args)) FileUtils.touch path generated_files << path end |