Skip to content

Commit cccca5b

Browse files
committed
Address comments
1 parent 6e855e5 commit cccca5b

File tree

5 files changed

+259
-199
lines changed

5 files changed

+259
-199
lines changed

rosidl_gen/generate_worker.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright (c) 2025, The Robot Web Tools Contributors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
const fse = require('fs-extra');
16+
const generateJSStructFromIDL = require('./idl_generator.js');
17+
const packages = require('./packages.js');
18+
const path = require('path');
19+
const idlConvertor = require('../rosidl_convertor/idl_convertor.js');
20+
21+
const generatedRoot = path.join(__dirname, '../generated/');
22+
const idlPath = path.join(generatedRoot, 'share');
23+
const useIDL = !!process.argv.find((arg) => arg === '--idl');
24+
25+
// Get target path from environment variable instead of workerData
26+
const targetPath = process.env.WORKER_TARGET_PATH;
27+
28+
async function generateInPath(targetPath) {
29+
let pkgsInfo = null;
30+
if (!useIDL) {
31+
pkgsInfo = Array.from(
32+
(await packages.findPackagesInDirectory(targetPath)).values()
33+
);
34+
} else {
35+
const idlPkgs = await packages.findPackagesInDirectory(targetPath, useIDL);
36+
await fse.ensureDir(idlPath);
37+
const promises = [];
38+
idlPkgs.forEach((pkg) => {
39+
pkg.idls.forEach((idl) => {
40+
promises.push(idlConvertor(idl.pkgName, idl.filePath, idlPath));
41+
});
42+
});
43+
await Promise.all(promises);
44+
const pkgsFromIdl = await packages.findPackagesInDirectory(idlPath, false);
45+
pkgsInfo = Array.from(pkgsFromIdl.values());
46+
}
47+
48+
await Promise.all(
49+
pkgsInfo.map((pkgInfo) => generateJSStructFromIDL(pkgInfo, generatedRoot))
50+
);
51+
}
52+
53+
async function main() {
54+
try {
55+
await generateInPath(targetPath);
56+
process.exit(0);
57+
} catch (error) {
58+
console.error('Worker generation failed:', error.message);
59+
process.exit(1);
60+
}
61+
}
62+
63+
main();

rosidl_gen/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ async function generateInPath(path) {
5555
}
5656

5757
function generateInPathSyncWorker(targetPath) {
58-
console.log('generateInPathSyncWorker' + targetPath);
5958
try {
6059
// Use child_process.spawnSync for truly synchronous execution
6160
const result = require('child_process').spawnSync(
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
msg/Point.idl
2-
msg/Point.msg
2+
msg/Point.msg
3+
msg/Testing.idl
4+
msg/Testing.msg

test/test-message-object.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ describe('Rclnodejs createMessage() testing', function () {
149149
it('expecting exception when passing ' + testData.toString(), function () {
150150
assert.throws(
151151
() => {
152-
const t = rclnodejs.createMessage(testData);
153-
console.log(t);
152+
rclnodejs.createMessage(testData);
154153
},
155154
function (e) {
156155
return e instanceof Error;

0 commit comments

Comments
 (0)