Skip to content

Commit 01813b9

Browse files
committed
Address comments
1 parent c3d23cb commit 01813b9

File tree

3 files changed

+48
-40
lines changed

3 files changed

+48
-40
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ To generate messages from IDL files, use the `generate-messages-idl` npm script:
140140
npm run generate-messages-idl
141141
```
142142

143+
\* This step is not needed for rclnodejs > 1.5.0
144+
143145
## Performance Benchmarks
144146

145147
Benchmark results for 1000 iterations with 1024KB messages (Ubuntu 24.04.3 WSL2, i7-1185G7):

lib/interface_loader.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ let interfaceLoader = {
9393
_searchAndGenerateInterface(packageName, type, messageName, filePath) {
9494
// Check if it's a valid package
9595
for (const pkgPath of generator.getInstalledPackagePaths()) {
96+
// We are going to ignore the path ROS2 installed.
9697
if (pkgPath.includes('ros2-linux')) {
9798
continue;
9899
}
@@ -122,14 +123,15 @@ let interfaceLoader = {
122123
}
123124
} catch (err) {
124125
// Skip directories we can't read
125-
console.log('Error reading directory:', dir, err.message);
126+
console.error('Error reading directory:', dir, err.message);
126127
}
127128
return null;
128129
}
129130

130131
const foundFilePath = searchForFile(
131132
path.join(pkgPath, 'share', packageName)
132133
);
134+
133135
if (foundFilePath && foundFilePath.length > 0) {
134136
// Use worker thread to generate interfaces synchronously
135137
try {
@@ -141,10 +143,6 @@ let interfaceLoader = {
141143
} catch (err) {
142144
console.error('Error in interface generation:', err);
143145
}
144-
} else {
145-
throw new Error(
146-
`The message required does not exist: ${packageName}, ${type}, ${messageName} at ${generator.generatedRoot}`
147-
);
148146
}
149147
}
150148
}

test/test-rosidl-message-generator.js

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,11 @@ const os = require('os');
1919
const rclnodejs = require('../index.js');
2020
const path = require('path');
2121

22-
function buildTestMessage() {
23-
// Build the custom_msg_test package synchronously before running the test
24-
const customMsgTestPath = path.join(__dirname, 'custom_msg_test');
25-
const buildResult = require('child_process').spawnSync('colcon', ['build'], {
26-
cwd: customMsgTestPath,
27-
stdio: 'inherit',
28-
timeout: 60000, // 60 second timeout
29-
});
30-
31-
if (buildResult.error) {
32-
throw new Error(
33-
`Failed to build custom_msg_test package: ${buildResult.error.message}`
34-
);
35-
}
36-
37-
if (buildResult.status !== 0) {
38-
throw new Error(`colcon build failed with exit code ${buildResult.status}`);
39-
}
40-
22+
function sourceSetupScript(setupPath) {
4123
// Source the local_setup.sh to get environment variables
42-
const setupScriptPath = path.join(
43-
customMsgTestPath,
44-
'install',
45-
'local_setup.sh'
46-
);
4724
const sourceResult = require('child_process').spawnSync(
4825
'bash',
49-
['-c', `source ${setupScriptPath} && env`],
26+
['-c', `source ${setupPath} && env`],
5027
{
5128
encoding: 'utf8',
5229
timeout: 10000, // 10 second timeout
@@ -83,6 +60,34 @@ function buildTestMessage() {
8360
});
8461
}
8562

63+
function buildTestMessage() {
64+
// Build the custom_msg_test package synchronously before running the test
65+
const customMsgTestPath = path.join(__dirname, 'custom_msg_test');
66+
const buildResult = require('child_process').spawnSync('colcon', ['build'], {
67+
cwd: customMsgTestPath,
68+
stdio: 'inherit',
69+
timeout: 60000, // 60 second timeout
70+
});
71+
72+
if (buildResult.error) {
73+
throw new Error(
74+
`Failed to build custom_msg_test package: ${buildResult.error.message}`
75+
);
76+
}
77+
78+
if (buildResult.status !== 0) {
79+
throw new Error(`colcon build failed with exit code ${buildResult.status}`);
80+
}
81+
82+
// Source the local_setup.sh to get environment variables
83+
const setupScriptPath = path.join(
84+
customMsgTestPath,
85+
'install',
86+
'local_setup.sh'
87+
);
88+
sourceSetupScript(setupScriptPath);
89+
}
90+
8691
describe('ROSIDL Node.js message generator test suite', function () {
8792
this.timeout(60 * 1000);
8893

@@ -289,15 +294,18 @@ describe('ROSIDL Node.js message generator test suite', function () {
289294

290295
it('Generate message at runtime', function () {
291296
const amentPrefixPathOriginal = process.env.AMENT_PREFIX_PATH;
292-
buildTestMessage();
293-
294-
assert.doesNotThrow(() => {
295-
const Testing = rclnodejs.require('custom_msg_test/msg/Testing');
296-
const t = new Testing();
297-
assert.equal(typeof t, 'object');
298-
assert.equal(typeof t.x, 'number');
299-
assert.equal(typeof t.data, 'string');
300-
}, 'This function should not throw');
301-
process.env.AMENT_PREFIX_PATH = amentPrefixPathOriginal;
297+
try {
298+
buildTestMessage();
299+
300+
assert.doesNotThrow(() => {
301+
const Testing = rclnodejs.require('custom_msg_test/msg/Testing');
302+
const t = new Testing();
303+
assert.equal(typeof t, 'object');
304+
assert.equal(typeof t.x, 'number');
305+
assert.equal(typeof t.data, 'string');
306+
}, 'This function should not throw');
307+
} finally {
308+
process.env.AMENT_PREFIX_PATH = amentPrefixPathOriginal;
309+
}
302310
});
303311
});

0 commit comments

Comments
 (0)