Repository: ros/ros_comm

Issue:
Allow empty machine attribute
Allowing empty machine attribute of node tag would help to make a launch-files with optional machine argument.

An example:

```
<arg name="machine" default=""/>
<node name="some_name" pkg="some_pkg" type="some_type" machine="$(arg machine)"/>
```



Discussion:
Wouldn't it be sufficient if you use `localhost` / `127.0.0.1`?

It would, but it require to have defined localhost as a machine in every such launchfile.

I still think that allow machine to be empty would be the better solution.

This is what you are suggesting?

```
<machine name="localhost" address="localhost" env-loader="/opt/ros/hydro/env.sh"/>
<arg name="machine" default="localhost"/>
<node name="some_name" pkg="some_pkg" type="some_type" machine="$(arg machine)"/>
```

None of the attributes in roslaunch currently supports this kind of behavior. In order to stay consistent that rule would need to apply to all attributes (e.g. `ns` attribute of the `group` tag).

This would require some effort to investigate the effect on all attributes and describing the consequences of such a change. Since the maintainers do not have the time to address this in the near future the issue will be marked with the milestone _untargeted_.

Any contribution on this is highly welcome.

@dirk-thomas @liborw I've got the same issue.
How about to take `localhost` as a type of reserved word, and if node are written in launch files with `machine="localhost"`, launch the node even if there is no declaration of `<machine name="localhost" address="localhost" />`?

In the meantime some attributes started to allow empty values (e.g. the include tag #882). So allowing an empty machine tag doesn't sound that different anymore. A generic approach (optional attributes with an empty value are considered equal to the attribute not being specified) would be preferred. But any pull request would be appreciated. Also if it only implements the handling of an empty machine tag.


Resolving patch:
diff --git a/tools/roslaunch/src/roslaunch/xmlloader.py b/tools/roslaunch/src/roslaunch/xmlloader.py
--- a/tools/roslaunch/src/roslaunch/xmlloader.py
+++ b/tools/roslaunch/src/roslaunch/xmlloader.py
@@ -388,8 +388,6 @@ def _node_tag(self, tag, context, ros_config, default_machine, is_test=False, ve
                     required = self.opt_attrs(tag, context, ('machine', 'args',
                         'output', 'respawn', 'respawn_delay', 'cwd',
                         'launch-prefix', 'required'))
-            if tag.hasAttribute('machine') and not len(machine.strip()):
-                raise XmlParseException("<node> 'machine' must be non-empty: [%s]"%machine)
             if not machine and default_machine:
                 machine = default_machine.name
             # validate respawn, required


Test patch:
diff --git a/tools/roslaunch/test/unit/test_xmlloader.py b/tools/roslaunch/test/unit/test_xmlloader.py
--- a/tools/roslaunch/test/unit/test_xmlloader.py
+++ b/tools/roslaunch/test/unit/test_xmlloader.py
@@ -757,7 +757,6 @@ def test_node_invalid(self):
                  'test-node-invalid-name-1.xml',
                  'test-node-invalid-name-2.xml',
                  'test-node-invalid-name-3.xml',
-                 'test-node-invalid-machine.xml',
                  'test-node-invalid-respawn.xml',
                  'test-node-invalid-respawn-required.xml',                 
                  'test-node-invalid-required-1.xml',
diff --git a/tools/roslaunch/test/xml/test-node-invalid-machine.xml b/tools/roslaunch/test/xml/test-node-invalid-machine.xml
deleted file mode 100644
--- a/tools/roslaunch/test/xml/test-node-invalid-machine.xml
+++ /dev/null
@@ -1,3 +0,0 @@
-<launch>
-  <node name="n" pkg="package" type="test_ns_invalid" machine="" />
-</launch>