Skip to content

Commit

Permalink
feat: readding MESSAGE_PATHS. introducing an override to specify an a…
Browse files Browse the repository at this point in the history
…bs path for js messages
  • Loading branch information
mbittarelli6river committed Feb 14, 2020
1 parent 834c972 commit 437bb17
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/ros_msg_utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ module.exports = {
Find: MessageCache.Find,
CMAKE_PREFIX_PATH: MessageCache.CMAKE_PREFIX_PATH,
CMAKE_PATHS: MessageCache.CMAKE_PATHS,
MESSAGE_PATH: MessageCache.MESSAGE_PATH,
packageMap: MessageCache.packageMap
};
14 changes: 12 additions & 2 deletions src/ros_msg_utils/lib/message_cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@
const fs = require('fs');
const path = require('path');

const CMAKE_PREFIX_PATH = process.env.CMAKE_PREFIX_PATH;
// before requiring this module, set the environment variable: process.env.JS_MESSAGE_ABS_PATH_OVERRIDE
// in order to to provide an absolute path to the directory containing all projects where generated JS ros messages are located
const CMAKE_PREFIX_PATH = process.env.JS_MESSAGE_ABS_PATH_OVERRIDE ? process.env.JS_MESSAGE_ABS_PATH_OVERRIDE : process.env.CMAKE_PREFIX_PATH;
const cmakePaths = CMAKE_PREFIX_PATH.split(path.delimiter);
const jsMsgPath = path.join('share', 'gennodejs', 'ros');

//-----------------------------------------------------------------------
// Search through the CMAKE_PREFIX_PATH for generated javascript messages.
Expand All @@ -31,7 +34,13 @@ const cmakePaths = CMAKE_PREFIX_PATH.split(path.delimiter);
//-----------------------------------------------------------------------
const packagePaths = {};
cmakePaths.forEach((cmakePath) => {
const dirPath = cmakePath;
let dirPath = null;
if(JS_MESSAGE_ABS_PATH_OVERRIDE) {
dirPath = cmakePath;
}
else {
dirPath = path.join(cmakePath, jsMsgPath);
}
try {
let msgPackages = fs.readdirSync(dirPath);
msgPackages.forEach((msgPackage) => {
Expand All @@ -58,5 +67,6 @@ module.exports = {

CMAKE_PREFIX_PATH,
CMAKE_PATHS: cmakePaths,
MESSAGE_PATH: jsMsgPath,
packageMap: Object.assign({}, packagePaths)
};
5 changes: 4 additions & 1 deletion src/utils/message_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ function copyFile(from, to, replaceCallback) {

let MessageUtils = {
getTopLevelMessageDirectory() {
return ros_msg_utils.CMAKE_PATHS[0];
if(process.env.JS_MESSAGE_ABS_PATH_OVERRIDE) {
return process.env.JS_MESSAGE_ABS_PATH_OVERRIDE;
}
return path.join(ros_msg_utils.CMAKE_PATHS[0], ros_msg_utils.MESSAGE_PATH);
},

flatten(outputDir) {
Expand Down

0 comments on commit 437bb17

Please sign in to comment.