def generate(args): """ Generate a message @param msg_path: The path to the .msg file @type msg_path: str """ log("generate(%s)" % args) from optparse import OptionParser parser = OptionParser("generates c++ message serialization code") parser.add_option('-p', dest='package', help="package name") parser.add_option('-o', dest='outdir', help="absolute path to output directory") parser.add_option('-I', dest='includepath', help="include path to search for messages", action='append') (options, args) = parser.parse_args(args) if not isinstance(options.includepath, list): options.includepath = [] # print "input==", options.input, "outdir==", options.outdir # package = os.path.basename # (package_dir, package) = rosidl.packages.get_dir_pkg(args[1]) rosidl.msgs._init() (_, spec) = rosidl.msgs.load_from_file(args[1], options.package) plog("spec", spec) s = StringIO() write_begin(s, spec, args[1]) write_generic_includes(s) write_includes(s, spec) cpp_prefix = '%s::' % (options.package) s.write('namespace %s\n{\n' % (options.package)) write_struct(s, spec, cpp_prefix, options.includepath) write_constant_definitions(s, spec) write_ostream_operator(s, spec, cpp_prefix) s.write('} // namespace %s\n\n' % (options.package)) write_traits(s, spec, cpp_prefix, options.includepath) write_serialization(s, spec, cpp_prefix) write_operations(s, spec, cpp_prefix) if options.package == "std_msgs" and spec.short_name == "Header": s.write("#define STD_MSGS_INCLUDING_HEADER_DEPRECATED_DEF 1\n") s.write("#include <std_msgs/header_deprecated_def.h>\n") s.write("#undef STD_MSGS_INCLUDING_HEADER_DEPRECATED_DEF\n\n") write_end(s, spec) if 'ROS_BUILD' in os.environ: package_dir = os.environ['ROS_BUILD'] odir = os.path.join(options.outdir, options.package) if (not os.path.exists(odir)): # if we're being run concurrently, the above test can report false but os.makedirs can still fail if # another copy just created the directory try: os.makedirs(odir) except OSError, e: pass
def generate(args): """ Generate a message @param msg_path: The path to the .msg file @type msg_path: str """ log("generate(%s)" % args) from optparse import OptionParser parser = OptionParser("generates c++ message serialization code") parser.add_option('-p', dest='package', help="package name") parser.add_option('-o', dest='outdir', help="absolute path to output directory") parser.add_option('-I', dest='includepath', help="include path to search for messages", action='append') (options, args) = parser.parse_args(args) if not isinstance(options.includepath, list): options.includepath = [] # print "input==", options.input, "outdir==", options.outdir # package = os.path.basename # (package_dir, package) = rosidl.packages.get_dir_pkg(args[1]) rosidl.msgs._init() (_, spec) = rosidl.msgs.load_from_file(args[1], options.package) plog("spec", spec) s = StringIO() write_begin(s, spec, args[1]) write_generic_includes(s) write_includes(s, spec) cpp_prefix = '%s::'%(options.package) s.write('namespace %s\n{\n'%(options.package)) write_struct(s, spec, cpp_prefix, options.includepath) write_constant_definitions(s, spec) write_ostream_operator(s, spec, cpp_prefix) s.write('} // namespace %s\n\n'%(options.package)) write_traits(s, spec, cpp_prefix, options.includepath) write_serialization(s, spec, cpp_prefix) write_operations(s, spec, cpp_prefix) if options.package == "std_msgs" and spec.short_name == "Header": s.write("#define STD_MSGS_INCLUDING_HEADER_DEPRECATED_DEF 1\n") s.write("#include <std_msgs/header_deprecated_def.h>\n") s.write("#undef STD_MSGS_INCLUDING_HEADER_DEPRECATED_DEF\n\n") write_end(s, spec) if 'ROS_BUILD' in os.environ: package_dir = os.environ['ROS_BUILD'] odir = os.path.join(options.outdir, options.package) if (not os.path.exists(odir)): # if we're being run concurrently, the above test can report false but os.makedirs can still fail if # another copy just created the directory try: os.makedirs(odir) except OSError, e: pass
def get_dependencies(spec, package, includepath, compute_files=True, stdout=sys.stdout, stderr=sys.stderr): """ Compute dependencies of the specified Msgs/Srvs @param spec: message or service instance @type spec: L{rosidl.msgs.MsgSpec}/L{rosidl.srvs.SrvSpec} @param package: package name @type package: str @param stdout: (optional) stdout pipe @type stdout: file @param stderr: (optional) stderr pipe @type stderr: file @param compute_files: (optional, default=True) compute file dependencies of message ('files' key in return value) @type compute_files: bool @return: dict: * 'files': list of files that \a file depends on * 'deps': list of dependencies by type * 'spec': Msgs/Srvs instance. * 'uniquedeps': list of dependencies with duplicates removed, * 'package': package that dependencies were generated relative to. @rtype: dict """ # #518: as a performance optimization, we're going to manually control the loading # of msgs instead of doing package-wide loads. #we're going to manipulate internal apis of msgs, so have to #manually init rosidl.msgs._init() deps = [] if isinstance(spec, rosidl.msgs.MsgSpec): _add_msgs_depends(spec, deps, package, includepath) elif isinstance(spec, rosidl.srvs.SrvSpec): _add_msgs_depends(spec.request, deps, package, includepath) _add_msgs_depends(spec.response, deps, package, includepath) else: raise Exception("[%s] does not appear to be a message or service"%spec) # convert from type names to file names if compute_files: files = {} for d in set(deps): d_pkg, t = rosidl.names.package_resource_name(d) d_pkg = d_pkg or package # convert '' -> local package files[d] = rosidl.msgs.msg_file(d_pkg, t, includepath) else: files = None # create unique dependency list uniquedeps = [] for d in deps: if not d in uniquedeps: uniquedeps.append(d) plog("uniquedeps", uniquedeps) if compute_files: return { 'files': files, 'deps': deps, 'spec': spec, 'package': package, 'uniquedeps': uniquedeps } else: return { 'deps': deps, 'spec': spec, 'package': package, 'uniquedeps': uniquedeps }