Skip to content

Commit 655cd4e

Browse files
committed
Remove invalid escape sequence
1 parent 8d0b4bf commit 655cd4e

File tree

2 files changed

+86
-68
lines changed

2 files changed

+86
-68
lines changed

binding.gyp

Lines changed: 17 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
'variables': {
1111
'ros_version': '<!(node scripts/ros_distro.js)',
1212
'runtime%': 'node',
13+
'ros_lib_dir': "<!(node -p \"require('./scripts/config.js').getROSLibPath()\")",
14+
'ros_include_root': "<!(node -p \"require('./scripts/config.js').getROSIncludeRootPath()\")",
1315
},
1416
'targets': [
1517
{
@@ -28,6 +30,7 @@
2830
'include_dirs': [
2931
'.',
3032
"<!(node -e \"require('nan')\")",
33+
'<(ros_include_root)',
3134
],
3235
'cflags!': [
3336
'-fno-exceptions'
@@ -61,40 +64,7 @@
6164
],
6265
'cflags_cc': [
6366
'-std=c++20'
64-
],
65-
'include_dirs':
66-
[
67-
"<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/:/g, '/include/ ') + '/include/')\")",
68-
],
69-
'library_dirs': [
70-
"<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/:/g, '/lib/ ') + '/lib/')\")",
71-
],
72-
'conditions': [
73-
[
74-
'ros_version > 2105', # Humble, Rolling, ...
75-
{
76-
'include_dirs':
77-
[
78-
"<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/:/g, '/include/ ') + '/include/')\")",
79-
"<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/:/g, '/include/rcl/ ') + '/include/rcl')\")",
80-
"<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/:/g, '/include/rcutils/ ') + '/include/rcutils/')\")",
81-
"<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/:/g, '/include/rmw/ ') + '/include/rmw/')\")",
82-
"<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/:/g, '/include/rcl_yaml_param_parser/ ') + '/include/rcl_yaml_param_parser/')\")",
83-
"<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/:/g, '/include/rosidl_typesupport_interface/ ') + '/include/rosidl_typesupport_interface/')\")",
84-
"<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/:/g, '/include/rcl_action/ ') + '/include/rcl_action/')\")",
85-
"<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/:/g, '/include/action_msgs/ ') + '/include/action_msgs/')\")",
86-
"<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/:/g, '/include/service_msgs/ ') + '/include/service_msgs/')\")",
87-
"<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/:/g, '/include/unique_identifier_msgs/ ') + '/include/unique_identifier_msgs/')\")",
88-
"<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/:/g, '/include/builtin_interfaces/ ') + '/include/builtin_interfaces/')\")",
89-
"<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/:/g, '/include/rcl_lifecycle/ ') + '/include/rcl_lifecycle/')\")",
90-
"<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/:/g, '/include/lifecycle_msgs/ ') + '/include/lifecycle_msgs/')\")",
91-
"<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/:/g, '/include/rosidl_runtime_c/ ') + '/include/rosidl_runtime_c/')\")",
92-
"<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/:/g, '/include/rosidl_dynamic_typesupport/ ') + '/include/rosidl_dynamic_typesupport/')\")",
93-
"<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/:/g, '/include/type_description_interfaces/ ') + '/include/type_description_interfaces/')\")",
94-
],
95-
}
96-
],
97-
],
67+
]
9868
}
9969
],
10070
[
@@ -108,42 +78,16 @@
10878
],
10979
'include_dirs': [
11080
'./src/third_party/dlfcn-win32/',
111-
"<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/;/g, '/include ').replace(/\\\/g, '/') + '/include')\")",
11281
],
11382
'msvs_settings': {
11483
'VCCLCompilerTool': {
11584
'ExceptionHandling': '2', # /EHsc
11685
},
11786
'VCLinkerTool': {
11887
'AdditionalDependencies': ['psapi.lib'],
119-
'AdditionalLibraryDirectories': ["<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/;/g, '\\\lib ').replace(/\\\/g, '/') + '/lib')\")",],
88+
'AdditionalLibraryDirectories': ['<(ros_lib_dir)'],
12089
}
121-
},
122-
'conditions': [
123-
[
124-
'ros_version > 2105', # Humble, Rolling, ... TODO - not tested due to broken setup_ros v3.3 action on windows
125-
{
126-
'include_dirs':
127-
[
128-
"<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/;/g, '/include/rcl ').replace(/\\\/g, '/') + '/include/rcl')\")",
129-
"<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/;/g, '/include/rcutils ').replace(/\\\/g, '/') + '/include/rcutils')\")",
130-
"<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/;/g, '/include/rmw ').replace(/\\\/g, '/') + '/include/rmw')\")",
131-
"<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/;/g, '/include/rcl_yaml_param_parser ').replace(/\\\/g, '/') + '/include/rcl_yaml_param_parser')\")",
132-
"<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/;/g, '/include/rosidl_runtime_c ').replace(/\\\/g, '/') + '/include/rosidl_runtime_c')\")",
133-
"<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/;/g, '/include/rosidl_typesupport_interface ').replace(/\\\/g, '/') + '/include/rosidl_typesupport_interface')\")",
134-
"<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/;/g, '/include/rcl_action ').replace(/\\\/g, '/') + '/include/rcl_action')\")",
135-
"<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/;/g, '/include/action_msgs ').replace(/\\\/g, '/') + '/include/action_msgs')\")",
136-
"<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/;/g, '/include/service_msgs ').replace(/\\\/g, '/') + '/include/service_msgs')\")",
137-
"<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/;/g, '/include/unique_identifier_msgs ').replace(/\\\/g, '/') + '/include/unique_identifier_msgs')\")",
138-
"<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/;/g, '/include/builtin_interfaces ').replace(/\\\/g, '/') + '/include/builtin_interfaces')\")",
139-
"<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/;/g, '/include/rcl_lifecycle ').replace(/\\\/g, '/') + '/include/rcl_lifecycle')\")",
140-
"<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/;/g, '/include/lifecycle_msgs ').replace(/\\\/g, '/') + '/include/lifecycle_msgs')\")",
141-
"<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/;/g, '/include/rosidl_dynamic_typesupport ').replace(/\\\/g, '/') + '/include/rosidl_dynamic_typesupport')\")",
142-
"<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/;/g, '/include/type_description_interfaces/ ').replace(/\\\/g, '/') + '/include/type_description_interfaces/')\")",
143-
],
144-
}
145-
]
146-
]
90+
}
14791
}
14892
],
14993
[
@@ -153,12 +97,6 @@
15397
'defines': [
15498
'OS_MACOS'
15599
],
156-
'include_dirs': [
157-
"<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/:/g, '/include/ ') + '/include/')\")",
158-
],
159-
'library_dirs': [
160-
"<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/:/g, '/lib/ ') + '/lib/')\")",
161-
],
162100
'xcode_settings': {
163101
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
164102
'CLANG_CXX_LIBRARY': 'libc++',
@@ -178,6 +116,17 @@
178116
]
179117
}
180118
],
119+
[
120+
'ros_version > 2105', # After Galactic, e.g., Humble, Jazzy, Rolling.
121+
{
122+
'include_dirs': [
123+
"<!@(node -e \"console.log(require('./scripts/config.js').getIncludePaths().map(p => {console.log(JSON.stringify(p)); return JSON.stringify(p);}))\")"
124+
],
125+
'library_dirs': [
126+
'<(ros_lib_dir)',
127+
]
128+
}
129+
],
181130
['runtime=="electron"', {
182131
"defines": ["NODE_RUNTIME_ELECTRON=1"]
183132
}],

scripts/config.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Licensed under the Apache License, Version 2.0 (the "License");
2+
// you may not use this file except in compliance with the License.
3+
// You may obtain a copy of the License at
4+
//
5+
// http://www.apache.org/licenses/LICENSE-2.0
6+
//
7+
// Unless required by applicable law or agreed to in writing, software
8+
// distributed under the License is distributed on an "AS IS" BASIS,
9+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
// See the License for the specific language governing permissions and
11+
// limitations under the License.
12+
13+
'use strict';
14+
15+
const os = require('os');
16+
const path = require('path');
17+
const { execSync } = require('child_process');
18+
19+
const dependencies = [
20+
'rcl',
21+
'rcutils',
22+
'rmw',
23+
'rcl_yaml_param_parser',
24+
'rosidl_typesupport_interface',
25+
'rcl_action',
26+
'action_msgs',
27+
'service_msgs',
28+
'unique_identifier_msgs',
29+
'builtin_interfaces',
30+
'rcl_lifecycle',
31+
'lifecycle_msgs',
32+
'rosidl_runtime_c',
33+
'rosidl_dynamic_typesupport',
34+
'type_description_interfaces',
35+
];
36+
const command = os.type() === 'Windows_NT' ? 'where ros2' : 'which ros2';
37+
38+
function getROSRootPath() {
39+
try {
40+
// Execute the command to find the ROS2 installation path.
41+
let ros2Path = execSync(command).toString().trim();
42+
return path.dirname(path.dirname(ros2Path));
43+
} catch (error) {
44+
console.error(`Error: ${error.message}`);
45+
}
46+
}
47+
48+
function getROSLibPath() {
49+
return path.join(getROSRootPath(), 'lib');
50+
}
51+
52+
function getROSIncludeRootPath() {
53+
return path.join(getROSRootPath(), 'include');
54+
}
55+
56+
function getIncludePaths() {
57+
const rosRoot = getROSRootPath();
58+
const includeDirs = dependencies.map((dependency) => {
59+
return path.join(rosRoot, 'include', dependency);
60+
});
61+
return includeDirs;
62+
}
63+
64+
module.exports = {
65+
getROSRootPath,
66+
getROSLibPath,
67+
getROSIncludeRootPath,
68+
getIncludePaths,
69+
};

0 commit comments

Comments
 (0)