Exemplo n.º 1
0
def generate_srv_from_spec(msg_context, spec, search_path, output_dir, package, path):
    "Generate code from .srv file"
    genmsg.msg_loader.load_depends(msg_context, spec, search_path)
    ext = '.srv'
    srvs = [f[:-len(ext)] for f in os.listdir(os.path.dirname(path)) if f.endswith(ext)]
    for s in srvs:
        load_srv_from_file(msg_context, path, '%s/%s'%(package, s))

    ########################################
    # 1. Write the .l file
    ########################################

    io = StringIO()
    s = IndentedWriter(io)
    write_begin(s, spec, True)
    write_include(s, spec.request, is_srv=True)
    write_include(s, spec.response, is_srv=True)
    spec.request.actual_name='%sRequest'%spec.short_name
    spec.response.actual_name='%sResponse'%spec.short_name
    write_srv_component(s, spec.request, msg_context, spec)
    write_srv_component(s, spec.response, msg_context, spec)
    write_service_specific_methods(s, msg_context, spec)

    with open('%s/%s.l'%(output_dir, spec.short_name), 'w') as f:
        f.write(io.getvalue())
    io.close()
Exemplo n.º 2
0
def generate_srv_from_spec(msg_context, spec, search_path, output_dir, package,
                           path):
    "Generate code from .srv file"
    genmsg.msg_loader.load_depends(msg_context, spec, search_path)
    ext = '.srv'
    srvs = [
        f[:-len(ext)] for f in os.listdir(os.path.dirname(path))
        if f.endswith(ext)
    ]
    for s in srvs:
        load_srv_from_file(msg_context, path, '%s/%s' % (package, s))

    ########################################
    # 1. Write the .l file
    ########################################

    io = StringIO()
    s = IndentedWriter(io)
    write_begin(s, spec, True)
    write_include(s, spec.request, is_srv=True)
    write_include(s, spec.response, is_srv=True)
    spec.request.actual_name = '%sRequest' % spec.short_name
    spec.response.actual_name = '%sResponse' % spec.short_name
    write_srv_component(s, spec.request, msg_context, spec)
    write_srv_component(s, spec.response, msg_context, spec)
    write_service_specific_methods(s, msg_context, spec)

    with open('%s/%s.l' % (output_dir, spec.short_name), 'w') as f:
        f.write(io.getvalue())
    io.close()
Exemplo n.º 3
0
def generate_srv_from_spec(msg_context, spec, search_path, output_dir, package, path):
    "Generate code from .srv file"
    genmsg.msg_loader.load_depends(msg_context, spec, search_path)
    ext = '.srv'
    srv_path = os.path.dirname(path)
    srvs = msg_list(package, {package: [srv_path]}, ext)
    for srv in srvs:
        load_srv_from_file(msg_context, '%s/%s%s'%(srv_path, srv, ext), '%s/%s'%(package, srv))

    ########################################
    # 1. Write the .lisp file
    ########################################

    io = StringIO()
    s = IndentedWriter(io)
    write_begin(s, spec, True)
    spec.request.actual_name='%s-request'%spec.short_name
    spec.response.actual_name='%s-response'%spec.short_name
    write_srv_component(s, spec.request, msg_context, spec)
    s.newline()
    write_srv_component(s, spec.response, msg_context, spec)
    write_service_specific_methods(s, spec)
    
    with open('%s/%s.lisp'%(output_dir, spec.short_name), 'w') as f:
        f.write(io.getvalue())
    io.close()

    ########################################
    # 2. Write the _package file
    # for this service
    ########################################

    io = StringIO()
    s = IndentedWriter(io)
    write_accessor_exports(s, spec)
    with open('%s/_package_%s.lisp'%(output_dir, spec.short_name), 'w') as f:
        f.write(io.getvalue())
    io.close()

    ########################################
    # 3. Write the _package.lisp file
    ########################################

    io = StringIO()
    s = IndentedWriter(io)
    write_srv_exports(s, srvs, package)
    with open('%s/_package.lisp'%output_dir, 'w') as f:
        f.write(io.getvalue())
    io.close()

    ########################################
    # 4. Write the .asd file
    ########################################

    io = StringIO()
    s = IndentedWriter(io)
    write_srv_asd(s, package, srvs, msg_context)
    with open('%s/%s-srv.asd'%(output_dir, package), 'w') as f:
        f.write(io.getvalue())
    io.close()
Exemplo n.º 4
0
def generate_srv_from_spec(msg_context, spec, search_path, output_dir, package,
                           path):
    "Generate code from .srv file"
    output_file = '%s/lib/src/srvs/%s.dart' % (output_dir, spec.short_name)
    if not needs_update(path, output_file):
        return
    genmsg.msg_loader.load_depends(msg_context, spec, search_path)
    ext = '.srv'
    srv_path = os.path.dirname(path)
    srvs = msg_list(package, {package: [srv_path]}, ext)
    for srv in srvs:
        load_srv_from_file(msg_context, '%s/%s%s' % (srv_path, srv, ext),
                           '%s/%s' % (package, srv))

    src_dir = output_dir + '/lib/src/srvs'
    if (not os.path.exists(src_dir)):
        # 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(src_dir)
        except OSError as e:
            pass
    ########################################
    # 1. Write the .dart file
    ########################################

    io = StringIO()
    s = IndentedWriter(io)
    write_begin(s, spec, True)
    found_packages, local_deps = write_requires(s, spec.request, search_path,
                                                output_dir, None, None, True)
    write_requires(s, spec.response, search_path, output_dir, found_packages,
                   local_deps, True)
    spec.request.actual_name = '%sRequest' % spec.short_name
    spec.response.actual_name = '%sResponse' % spec.short_name
    write_srv_component(s, spec.request, msg_context, spec, search_path)
    write_srv_component(s, spec.response, msg_context, spec, search_path)
    write_srv_end(s, msg_context, spec)

    with open('%s/lib/src/srvs/%s.dart' % (output_dir, spec.short_name),
              'w') as f:
        f.write(io.getvalue())
    io.close()

    ########################################
    # 3. Write the srvs.dart file
    # This is being rewritten once per msg
    # file, which is inefficient
    ########################################
    io = StringIO()
    s = IndentedWriter(io)
    # print(srvs)
    write_srv_export(s, srvs, package)
    with open('{}/lib/srvs.dart'.format(output_dir), 'w') as f:
        f.write(io.getvalue())
    io.close()
Exemplo n.º 5
0
def generate_srv_from_spec(msg_context, spec, search_path, output_dir, package,
                           path):
    "Generate code from .srv file"
    genmsg.msg_loader.load_depends(msg_context, spec, search_path)
    ext = '.srv'
    srv_path = os.path.dirname(path)
    srvs = msg_list(package, {package: [srv_path]}, ext)
    for srv in srvs:
        load_srv_from_file(msg_context, '%s/%s%s' % (srv_path, srv, ext),
                           '%s/%s' % (package, srv))

    ########################################
    # 1. Write the .js file
    ########################################

    io = StringIO()
    s = IndentedWriter(io)
    write_begin(s, spec, True)
    found_packages, local_deps = write_requires(s, spec.request, None, None,
                                                True)
    write_requires(s, spec.response, found_packages, local_deps, True)
    spec.request.actual_name = '%sRequest' % spec.short_name
    spec.response.actual_name = '%sResponse' % spec.short_name
    write_srv_component(s, spec.request, msg_context, spec, search_path)
    write_srv_component(s, spec.response, msg_context, spec, search_path)
    write_srv_end(s, msg_context, spec)

    with open('%s/%s.js' % (output_dir, spec.short_name), 'w') as f:
        f.write(io.getvalue())
    io.close()

    ########################################
    # 3. Write the msg/_index.js file
    # This is being rewritten once per msg
    # file, which is inefficient
    ########################################
    io = StringIO()
    s = IndentedWriter(io)
    write_srv_index(s, srvs, package)
    with open('{}/_index.js'.format(output_dir), 'w') as f:
        f.write(io.getvalue())
    io.close()

    ########################################
    # 3. Write the package _index.js file
    # This is being rewritten once per msg
    # file, which is inefficient
    ########################################
    io = StringIO()
    s = IndentedWriter(io)
    package_dir = os.path.dirname(output_dir)
    write_package_index(s, package_dir)
    with open('{}/_index.js'.format(package_dir), 'w') as f:
        f.write(io.getvalue())
    io.close()
Exemplo n.º 6
0
def generate_srv_from_spec(msg_context, spec, search_path, output_dir, package, path):
    "Generate code from .srv file"
    genmsg.msg_loader.load_depends(msg_context, spec, search_path)
    ext = '.srv'
    srv_path = os.path.dirname(path)
    srvs = msg_list(package, {package: [srv_path]}, ext)
    for srv in srvs:
        load_srv_from_file(msg_context, '%s/%s%s'%(srv_path, srv, ext), '%s/%s'%(package, srv))

    ########################################
    # 1. Write the .js file
    ########################################

    io = StringIO()
    s = IndentedWriter(io)
    write_begin(s, spec, True)
    found_packages,local_deps = write_requires(s, spec.request, None, None, True)
    write_requires(s, spec.response, found_packages, local_deps, True)
    spec.request.actual_name='%sRequest'%spec.short_name
    spec.response.actual_name='%sResponse'%spec.short_name
    write_srv_component(s, spec.request, msg_context, spec, search_path)
    write_srv_component(s, spec.response, msg_context, spec, search_path)
    write_srv_end(s, msg_context, spec)

    with open('%s/%s.js'%(output_dir, spec.short_name), 'w') as f:
        f.write(io.getvalue())
    io.close()

    ########################################
    # 3. Write the msg/_index.js file
    # This is being rewritten once per msg
    # file, which is inefficient
    ########################################
    io = StringIO()
    s = IndentedWriter(io)
    write_srv_index(s, srvs, package)
    with open('{}/_index.js'.format(output_dir), 'w') as f:
        f.write(io.getvalue())
    io.close()

    ########################################
    # 3. Write the package _index.js file
    # This is being rewritten once per msg
    # file, which is inefficient
    ########################################
    io = StringIO()
    s = IndentedWriter(io)
    package_dir = os.path.dirname(output_dir)
    write_package_index(s, package_dir)
    with open('{}/_index.js'.format(package_dir), 'w') as f:
        f.write(io.getvalue())
    io.close()
Exemplo n.º 7
0
def test_load_srv_from_file():
    from genmsg.msg_loader import MsgContext, load_srv_from_file

    msg_context = MsgContext.create_default()

    d = get_test_dir()
    filename = os.path.join(d, 'test_ros', 'srv', 'AddTwoInts.srv')
    with open(filename, 'r') as f:
        text = f.read()

    full_name = 'test_ros/AddTwoInts'
    spec = load_srv_from_file(msg_context, filename, full_name)
    assert spec == load_srv_from_file(msg_context, filename, full_name)
    assert ['int64', 'int64'] == spec.request.types, spec.request.types
    assert ['a', 'b'] == spec.request.names
    assert text == spec.text
    assert full_name == spec.full_name
Exemplo n.º 8
0
def test_load_srv_from_file():
    from genmsg.msg_loader import MsgContext, load_srv_from_file
        
    msg_context = MsgContext.create_default()
    
    d = get_test_dir()
    filename = os.path.join(d, 'test_ros', 'srv', 'AddTwoInts.srv')
    with open(filename, 'r') as f:
        text = f.read()
        
    full_name = 'test_ros/AddTwoInts'
    spec = load_srv_from_file(msg_context, filename, full_name)
    assert spec == load_srv_from_file(msg_context, filename, full_name)
    assert ['int64', 'int64'] == spec.request.types, spec.request.types
    assert ['a', 'b'] == spec.request.names
    assert text == spec.text
    assert full_name == spec.full_name
Exemplo n.º 9
0
def test_load_srv_from_file():
    from genmsg.msg_loader import MsgContext, load_srv_from_file

    msg_context = MsgContext.create_default()

    d = get_test_dir()
    filename = os.path.join(d, "test_ros", "srv", "AddTwoInts.srv")
    with open(filename, "r") as f:
        text = f.read()

    full_name = "test_ros/AddTwoInts"
    spec = load_srv_from_file(msg_context, filename, full_name)
    assert spec == load_srv_from_file(msg_context, filename, full_name)
    assert ["int64", "int64"] == spec.request.types, spec.request.types
    assert ["a", "b"] == spec.request.names
    assert text == spec.text
    assert full_name == spec.full_name
Exemplo n.º 10
0
def test_load_srv_with_string_constant_from_file():
    from genmsg.msg_loader import MsgContext, load_srv_from_file

    msg_context = MsgContext.create_default()

    d = get_test_dir()
    filename = os.path.join(d, 'test_ros', 'srv',
                            'ServiceWithStringConstant.srv')
    with open(filename, 'r') as f:
        text = f.read()

    full_name = 'test_ros/ServiceWithStringConstant'
    spec = load_srv_from_file(msg_context, filename, full_name)
    assert spec == load_srv_from_file(msg_context, filename, full_name)
    assert ['string'] == spec.request.types, spec.request.types
    assert ['value'] == spec.request.names
    assert ['return_value'] == spec.response.names
    assert len(spec.request.constants) == 2
    index_string = 0 if spec.request.constants[0].name == 'EXAMPLE' else 1
    index_int = 1 - index_string
    constant = spec.request.constants[index_string]
    assert constant.type == 'string'
    assert constant.name == 'EXAMPLE'
    assert constant.val == 'here "#comments" are ignored, and leading and trailing whitespace removed', '<{}>'.format(
        constant.val)
    constant = spec.request.constants[index_int]
    assert constant.type == 'int32'
    assert constant.name == 'INTCONST'
    assert constant.val == 42, '<{}>'.format(constant.val)
    assert len(spec.response.constants) == 1
    constant = spec.response.constants[0]
    assert constant.type == 'string'
    assert constant.name == 'RESULTEXAMPLE'
    assert constant.val == 'here "#comments" are ignored too, and leading and trailing whitespace removed', '<{}>'.format(
        constant.val)
    assert text == spec.text
    assert full_name == spec.full_name
Exemplo n.º 11
0
def find_package_info(requested_pkg_name):
    info = PackageInfo(requested_pkg_name)

    share_dir = g_manifest.get_path(requested_pkg_name)

    message_dir = '{}/msg'.format(share_dir)
    if os.path.exists(message_dir):
        for relative_msg_file in os.listdir(message_dir):
            if not relative_msg_file.endswith('.msg'):
                continue

            msg_file = '{}/{}'.format(message_dir, relative_msg_file)

            # Strip off the extension to get the local name of the message type
            msg_subname = relative_msg_file[:-4]

            info.msg_files.append(msg_file)
            msg = load_msg_from_file(
                g_msg_context, msg_file,
                '{}/{}'.format(requested_pkg_name, msg_subname))
            append_msg_dependencies(msg, info.dependencies)

    service_dir = '{}/srv'.format(share_dir)
    if os.path.exists(service_dir):
        for relative_srv_file in os.listdir(service_dir):
            if not relative_srv_file.endswith('.srv'):
                continue

            srv_file = '{}/{}'.format(service_dir, relative_srv_file)

            # Strip off the extension to get the local name of the service type
            srv_subname = relative_srv_file[:-4]

            info.srv_files.append(srv_file)
            srv = load_srv_from_file(
                g_msg_context, srv_file,
                '{}/{}'.format(requested_pkg_name, srv_subname))
            for component in [srv.request, srv.response]:
                append_msg_dependencies(component, info.dependencies)

    return info
Exemplo n.º 12
0
from genmsg import EXT_MSG, EXT_SRV, MsgContext
from genmsg.gentools import compute_full_type_name
from genmsg.msg_loader import load_msg_from_file, load_srv_from_file
from genmsg.msgs import bare_msg_type, is_builtin, resolve_type

pkg_name = sys.argv[1]
msg_file = sys.argv[2]
deps = sys.argv[3].split(':') if len(sys.argv) > 3 else []

msg_context = MsgContext.create_default()
full_type_name = compute_full_type_name(pkg_name, os.path.basename(msg_file))

if msg_file.endswith(EXT_MSG):
    spec = load_msg_from_file(msg_context, msg_file, full_type_name)
    unresolved_types = spec.types
elif msg_file.endswith(EXT_SRV):
    spec = load_srv_from_file(msg_context, msg_file, full_type_name)
    unresolved_types = spec.request.types + spec.response.types
else:
    print("Processing file: '%s' - unknown file extension" % msg_file, file=sys.stderr)
    sys.exit(1)

package_context = spec.package
for unresolved_type in unresolved_types:
    bare_type = bare_msg_type(unresolved_type)
    resolved_type = resolve_type(bare_type, package_context)
    if not is_builtin(resolved_type) and resolved_type not in deps:
        print("The dependencies of the message/service '%s' have changed. Please rerun cmake." % spec.full_name, file=sys.stderr)
        sys.exit(1)
Exemplo n.º 13
0
def parse_service_file(srv_file, srv_name):
    return load_srv_from_file(g_msg_context, srv_file, srv_name)
from genmsg.gentools import compute_full_type_name
from genmsg.msg_loader import load_msg_from_file, load_srv_from_file
from genmsg.msgs import bare_msg_type, is_builtin, resolve_type

pkg_name = sys.argv[1]
msg_file = sys.argv[2]
deps = sys.argv[3].split(':') if len(sys.argv) > 3 else []

msg_context = MsgContext.create_default()
full_type_name = compute_full_type_name(pkg_name, os.path.basename(msg_file))

if msg_file.endswith(EXT_MSG):
    spec = load_msg_from_file(msg_context, msg_file, full_type_name)
    unresolved_types = spec.types
elif msg_file.endswith(EXT_SRV):
    spec = load_srv_from_file(msg_context, msg_file, full_type_name)
    unresolved_types = spec.request.types + spec.response.types
else:
    print("Processing file: '%s' - unknown file extension" % msg_file,
          file=sys.stderr)
    sys.exit(1)

package_context = spec.package
for unresolved_type in unresolved_types:
    bare_type = bare_msg_type(unresolved_type)
    resolved_type = resolve_type(bare_type, package_context)
    if not is_builtin(resolved_type) and resolved_type not in deps:
        print(
            "The dependencies of the message/service '%s' have changed. Please rerun cmake."
            % spec.full_name,
            file=sys.stderr)