Skip to content

Commit b66f5b8

Browse files
koonpengMinggang Wang
authored andcommitted
fix compatibility for eloquent
v0.14.1 introduces support for ROS2 foxy however it also drops support for eloquent. This breaks existing users on v0.14.0+eloquent that expects api to remain stable when upgrading to a patch release.
1 parent 5b6a6fe commit b66f5b8

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

binding.gyp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
},
88
}
99
},
10+
'variables': {
11+
'ros_version': '<!(node scripts/ros_distro.js)'
12+
},
1013
'targets': [
1114
{
1215
'target_name': 'rclnodejs',
@@ -44,6 +47,9 @@
4447
'-lrmw',
4548
'-lrosidl_runtime_c',
4649
],
50+
'defines': [
51+
'ROS_VERSION=<(ros_version)'
52+
],
4753
'conditions': [
4854
[
4955
'OS=="linux"', {
@@ -104,6 +110,17 @@
104110
'CLANG_CXX_LANGUAGE_STANDARD': 'c++14'
105111
}
106112
}
113+
],
114+
[
115+
'ros_version<=1911',
116+
{
117+
'libraries': [
118+
'-lrosidl_generator_c'
119+
],
120+
'libraries!': [
121+
'-lrosidl_runtime_c'
122+
]
123+
}
107124
]
108125
]
109126
}

scripts/ros_distro.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
switch (process.env.ROS_DISTRO) {
4+
case 'eloquent':
5+
console.log('1911');
6+
process.exit(0);
7+
case 'foxy':
8+
console.log('2006');
9+
process.exit(0);
10+
case undefined:
11+
console.error('Unable to detect ROS, please make sure a supported version of ROS is sourced');
12+
process.exit(1);
13+
default:
14+
console.error(`Unknown or unsupported ROS version "${process.env.ROS_DISTRO}"`);
15+
process.exit(1);
16+
}

src/rcl_bindings.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@
3030
#include <rmw/validate_full_topic_name.h>
3131
#include <rmw/validate_namespace.h>
3232
#include <rmw/validate_node_name.h>
33+
#if ROS_VERSION >= 2006
3334
#include <rosidl_runtime_c/string_functions.h>
35+
#else
36+
#include <rosidl_generator_c/string_functions.h>
37+
#endif
3438

3539
#include <memory>
3640
#include <string>
@@ -1277,10 +1281,17 @@ NAN_METHOD(Shutdown) {
12771281
NAN_METHOD(InitString) {
12781282
void* buffer =
12791283
node::Buffer::Data(Nan::To<v8::Object>(info[0]).ToLocalChecked());
1284+
#if ROS_VERSION >= 2006
12801285
rosidl_runtime_c__String* ptr =
12811286
reinterpret_cast<rosidl_runtime_c__String*>(buffer);
12821287

12831288
rosidl_runtime_c__String__init(ptr);
1289+
#else
1290+
rosidl_generator_c__String* ptr =
1291+
reinterpret_cast<rosidl_generator_c__String*>(buffer);
1292+
1293+
rosidl_generator_c__String__init(ptr);
1294+
#endif
12841295
info.GetReturnValue().Set(Nan::Undefined());
12851296
}
12861297

0 commit comments

Comments
 (0)