Skip to content

Commit f644f49

Browse files
committed
Address comments
1 parent 01813b9 commit f644f49

1 file changed

Lines changed: 29 additions & 2 deletions

File tree

lib/interface_loader.js

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,38 @@ let interfaceLoader = {
9090
return pkg;
9191
},
9292

93+
_isRos2InstallationPath(pkgPath) {
94+
// Use "which ros2" to dynamically find the ROS2 installation root
95+
try {
96+
const whichResult = require('child_process').spawnSync(
97+
'which',
98+
['ros2'],
99+
{
100+
encoding: 'utf8',
101+
timeout: 5000,
102+
}
103+
);
104+
105+
if (whichResult.status === 0 && whichResult.stdout) {
106+
const ros2BinPath = whichResult.stdout.trim();
107+
// Get the ROS2 installation root (typically /opt/ros/<distro> or similar)
108+
const ros2Root = path.dirname(path.dirname(ros2BinPath));
109+
110+
return pkgPath.includes(ros2Root);
111+
}
112+
} catch (err) {
113+
// If "which ros2" fails, fall back to hardcoded check
114+
return pkgPath.includes('ros2-linux');
115+
}
116+
117+
return false;
118+
},
119+
93120
_searchAndGenerateInterface(packageName, type, messageName, filePath) {
94121
// Check if it's a valid package
95122
for (const pkgPath of generator.getInstalledPackagePaths()) {
96-
// We are going to ignore the path ROS2 installed.
97-
if (pkgPath.includes('ros2-linux')) {
123+
// We are going to ignore the path where ROS2 is installed.
124+
if (this._isRos2InstallationPath(pkgPath)) {
98125
continue;
99126
}
100127

0 commit comments

Comments
 (0)