Skip to content

Commit

Permalink
feat: MOVEMENT-1176 update ros package path - merge to kinetic-devel
Browse files Browse the repository at this point in the history
Feat/update ros package path MOVEMENT-1176
  • Loading branch information
mbittarelli6river authored Feb 20, 2020
2 parents fde67bf + a8df0f6 commit 75829be
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
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,7 +20,10 @@
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 JS_MESSAGE_ABS_PATH_OVERRIDE = process.env.JS_MESSAGE_ABS_PATH_OVERRIDE;
const CMAKE_PREFIX_PATH = JS_MESSAGE_ABS_PATH_OVERRIDE ? 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');

Expand All @@ -32,7 +35,13 @@ const jsMsgPath = path.join('share', 'gennodejs', 'ros');
//-----------------------------------------------------------------------
const packagePaths = {};
cmakePaths.forEach((cmakePath) => {
const dirPath = path.join(cmakePath, jsMsgPath);
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,6 +67,7 @@ module.exports = {
},

CMAKE_PREFIX_PATH,
JS_MESSAGE_ABS_PATH_OVERRIDE,
CMAKE_PATHS: cmakePaths,
MESSAGE_PATH: jsMsgPath,
packageMap: Object.assign({}, packagePaths)
Expand Down
2 changes: 1 addition & 1 deletion src/utils/messageGeneration/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ fields.getPrimitiveSize = function(fieldType, fieldValue) {
}
else if (fieldType === 'string') {
if (fieldValue !== undefined) {
fieldSize = fieldValue.length + 4;
fieldSize = Buffer.byteLength(fieldValue, 'utf8') + 4;
}
}
else if (fieldType === 'time') {
Expand Down
3 changes: 3 additions & 0 deletions src/utils/message_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ function copyFile(from, to, replaceCallback) {

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

Expand Down

0 comments on commit 75829be

Please sign in to comment.