Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion rosidl_gen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ const generateJSStructFromIDL = require('./idl_generator.js');
const packages = require('./packages.js');
const path = require('path');
const idlConvertor = require('../rosidl_convertor/idl_convertor.js');
const generatedRoot = path.join(__dirname, '../generated/');
const utils = require('./utils.js');

// Check if GENERATED_MSG_PATH environment variable exists and is valid
const generatedRoot = utils.getGeneratedRoot();
const serviceMsgPath = path.join(generatedRoot, 'srv_msg');
const idlPath = path.join(generatedRoot, 'share');
const useIDL = !!process.argv.find((arg) => arg === '--idl');
Expand Down
3 changes: 2 additions & 1 deletion rosidl_gen/packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ const path = require('path');
const walk = require('walk');
const os = require('os');
const pkgFilters = require('../rosidl_gen/filter.js');
const utils = require('./utils.js');

const fsp = fs.promises;

const generatedRoot = path.join(__dirname, '../generated/');
const generatedRoot = utils.getGeneratedRoot();
const serviceMsgPath = path.join(generatedRoot, 'srv_msg');

function getPackageName(filePath, amentExecuted) {
Expand Down
35 changes: 35 additions & 0 deletions rosidl_gen/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) 2025, The Robot Web Tools Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

const fse = require('fs-extra');
const path = require('path');

function getGeneratedRoot() {
let generatedRoot = path.join(__dirname, '../generated/');
if (process.env.GENERATED_MSG_PATH) {
if (fse.pathExistsSync(process.env.GENERATED_MSG_PATH)) {
generatedRoot = path.join(process.env.GENERATED_MSG_PATH, '/generated/');
console.log(generatedRoot);
} else {
console.log(
`Warning: GENERATED_MSG_PATH is set to '${process.env.GENERATED_MSG_PATH}' but the parent directory does not exist. Using default path instead.`
);
}
}
return generatedRoot;
}

module.exports = { getGeneratedRoot };
3 changes: 2 additions & 1 deletion rostsd_gen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ const path = require('path');
const fs = require('fs');
const loader = require('../lib/interface_loader.js');
const pkgFilters = require('../rosidl_gen/filter.js');
const utils = require('../rosidl_gen/utils.js');

const descriptorInterfaceNamespace = 'descriptor';

async function generateAll() {
// load pkg and interface info (msgs and srvs)
const generatedPath = path.join(__dirname, '../generated/');
const generatedPath = utils.getGeneratedRoot();
const pkgInfos = getPkgInfos(generatedPath);
if (pkgInfos.length === 0) {
console.log('No package found, prebuild interfaces.d.ts will be used.');
Expand Down
Loading