Skip to content

Commit cbd02f4

Browse files
committed
enviroment hooks to generate a ros maven path.
1 parent c831c46 commit cbd02f4

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ find_package(catkin REQUIRED)
1313
catkin_package(CFG_EXTRAS rosjava.cmake)
1414

1515
catkin_python_setup()
16+
catkin_add_env_hooks(15.rosjava SHELLS bash DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/env-hooks)
1617

1718
##############################################################################
1819
# Project Settings

env-hooks/15.rosjava.bash.em

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
@[if DEVELSPACE]@
4+
export ROS_MAVEN_PATH=`python @(CMAKE_CURRENT_SOURCE_DIR)/generate_ros_maven_path.py`
5+
@[else]@
6+
export ROS_MAVEN_PATH=`python @(CMAKE_INSTALL_PREFIX)/share/rosjava_tools/generate_ros_maven_path.py`
7+
@[end if]@
8+
9+

generate_ros_maven_path.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
3+
import os
4+
5+
CATKIN_MARKER_FILE = '.catkin'
6+
7+
def get_workspaces(environ):
8+
'''
9+
Based on CMAKE_PREFIX_PATH return all catkin workspaces.
10+
'''
11+
# get all cmake prefix paths
12+
env_name = 'CMAKE_PREFIX_PATH'
13+
value = environ[env_name] if env_name in environ else ''
14+
paths = [path for path in value.split(os.pathsep) if path]
15+
# remove non-workspace paths
16+
workspaces = [path for path in paths if os.path.isfile(os.path.join(path, CATKIN_MARKER_FILE)) or (include_fuerte and path.startswith('/opt/ros/fuerte'))]
17+
return workspaces
18+
19+
if __name__ == '__main__':
20+
workspaces = get_workspaces(dict(os.environ))
21+
maven_repository_paths = [os.path.join(path, 'maven') for path in workspaces]
22+
print os.pathsep.join(maven_repository_paths)

0 commit comments

Comments
 (0)