Skip to content

Commit 6c8d3ef

Browse files
committed
Set GENERATED_MSG_PATH as the path of the generated messages
1 parent 95b5609 commit 6c8d3ef

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

rosidl_gen/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ const generateJSStructFromIDL = require('./idl_generator.js');
1919
const packages = require('./packages.js');
2020
const path = require('path');
2121
const idlConvertor = require('../rosidl_convertor/idl_convertor.js');
22-
const generatedRoot = path.join(__dirname, '../generated/');
22+
const utils = require('./utils.js');
23+
24+
// Check if GENERATED_MSG_PATH environment variable exists and is valid
25+
const generatedRoot = utils.getGeneratedRoot();
2326
const serviceMsgPath = path.join(generatedRoot, 'srv_msg');
2427
const idlPath = path.join(generatedRoot, 'share');
2528
const useIDL = !!process.argv.find((arg) => arg === '--idl');

rosidl_gen/packages.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ const path = require('path');
2121
const walk = require('walk');
2222
const os = require('os');
2323
const pkgFilters = require('../rosidl_gen/filter.js');
24+
const utils = require('./utils.js');
2425

2526
const fsp = fs.promises;
2627

27-
const generatedRoot = path.join(__dirname, '../generated/');
28+
const generatedRoot = utils.getGeneratedRoot();
2829
const serviceMsgPath = path.join(generatedRoot, 'srv_msg');
2930

3031
function getPackageName(filePath, amentExecuted) {

rosidl_gen/utils.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
'use strict';
16+
17+
const fse = require('fs-extra');
18+
const path = require('path');
19+
20+
function getGeneratedRoot() {
21+
let generatedRoot = path.join(__dirname, '../generated/');
22+
if (process.env.GENERATED_MSG_PATH) {
23+
if (fse.pathExistsSync(process.env.GENERATED_MSG_PATH)) {
24+
generatedRoot = path.join(process.env.GENERATED_MSG_PATH, '/generated/');
25+
console.log(generatedRoot);
26+
} else {
27+
console.log(
28+
`Warning: GENERATED_MSG_PATH is set to '${process.env.GENERATED_MSG_PATH}' but the parent directory does not exist. Using default path instead.`
29+
);
30+
}
31+
}
32+
return generatedRoot;
33+
}
34+
35+
module.exports = { getGeneratedRoot };

rostsd_gen/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@ const path = require('path');
3030
const fs = require('fs');
3131
const loader = require('../lib/interface_loader.js');
3232
const pkgFilters = require('../rosidl_gen/filter.js');
33+
const utils = require('../rosidl_gen/utils.js');
3334

3435
const descriptorInterfaceNamespace = 'descriptor';
3536

3637
async function generateAll() {
3738
// load pkg and interface info (msgs and srvs)
38-
const generatedPath = path.join(__dirname, '../generated/');
39+
const generatedPath = utils.getGeneratedRoot();
3940
const pkgInfos = getPkgInfos(generatedPath);
4041
if (pkgInfos.length === 0) {
4142
console.log('No package found, prebuild interfaces.d.ts will be used.');

0 commit comments

Comments
 (0)