Skip to content

Commit 3b73e7e

Browse files
committed
fix problems with preset ros environment variables from a chained workspace.
1 parent 9697ec5 commit 3b73e7e

File tree

3 files changed

+42
-29
lines changed

3 files changed

+42
-29
lines changed

env-hooks/15.rosjava.bash.em

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,6 @@ SCRIPT=@(CMAKE_CURRENT_SOURCE_DIR)/generate_environment_variables.py
66
SCRIPT=@(CMAKE_INSTALL_PREFIX)/share/rosjava_build_tools/generate_environment_variables.py
77
@[end if]@
88

9-
# Conditionally set these variables - i.e. if the user wants to override them, that is ok.
10-
: ${ROS_MAVEN_PATH:=`python ${SCRIPT} --maven-path`}
11-
: ${ROS_MAVEN_DEPLOYMENT_REPOSITORY:=`python ${SCRIPT} --maven-deployment-repository`}
12-
: ${GRADLE_USER_HOME:=`python ${SCRIPT} --gradle-user-home`}
13-
export ROS_MAVEN_PATH
14-
export ROS_MAVEN_DEPLOYMENT_REPOSITORY
15-
export GRADLE_USER_HOME
16-
17-
#export ROS_MAVEN_PATH=`python @(CMAKE_CURRENT_SOURCE_DIR)/generate_environment_variables.py --maven-path`
18-
#export ROS_MAVEN_DEPLOYMENT_REPOSITORY=`python @(CMAKE_CURRENT_SOURCE_DIR)/generate_environment_variables.py --maven-deployment-repository`
19-
#export GRADLE_USER_HOME=`python @(CMAKE_CURRENT_SOURCE_DIR)/generate_environment_variables.py --gradle-user-home`
9+
export ROS_MAVEN_PATH=`python ${SCRIPT} --maven-path`
10+
export ROS_MAVEN_DEPLOYMENT_REPOSITORY=`python ${SCRIPT} --maven-deployment-repository`
11+
export GRADLE_USER_HOME=`python ${SCRIPT} --gradle-user-home`

env-hooks/15.rosjava.sh.em

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,6 @@ SCRIPT=@(CMAKE_CURRENT_SOURCE_DIR)/generate_environment_variables.py
66
SCRIPT=@(CMAKE_INSTALL_PREFIX)/share/rosjava_build_tools/generate_environment_variables.py
77
@[end if]@
88

9-
# Conditionally set these variables - i.e. if the user wants to override them, that is ok.
10-
: ${ROS_MAVEN_PATH:=`python ${SCRIPT} --maven-path`}
11-
: ${ROS_MAVEN_DEPLOYMENT_REPOSITORY:=`python ${SCRIPT} --maven-deployment-repository`}
12-
: ${GRADLE_USER_HOME:=`python ${SCRIPT} --gradle-user-home`}
13-
export ROS_MAVEN_PATH
14-
export ROS_MAVEN_DEPLOYMENT_REPOSITORY
15-
export GRADLE_USER_HOME
16-
17-
#export ROS_MAVEN_PATH=`python @(CMAKE_CURRENT_SOURCE_DIR)/generate_environment_variables.py --maven-path`
18-
#export ROS_MAVEN_DEPLOYMENT_REPOSITORY=`python @(CMAKE_CURRENT_SOURCE_DIR)/generate_environment_variables.py --maven-deployment-repository`
19-
#export GRADLE_USER_HOME=`python @(CMAKE_CURRENT_SOURCE_DIR)/generate_environment_variables.py --gradle-user-home`
9+
export ROS_MAVEN_PATH=`python ${SCRIPT} --maven-path`
10+
export ROS_MAVEN_DEPLOYMENT_REPOSITORY=`python ${SCRIPT} --maven-deployment-repository`
11+
export GRADLE_USER_HOME=`python ${SCRIPT} --gradle-user-home`

generate_environment_variables.py

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,46 @@ def get_workspaces(environ):
2626
workspaces = [path for path in paths if os.path.isfile(os.path.join(path, CATKIN_MARKER_FILE))]
2727
return workspaces
2828

29+
def get_environment_variable(environ, key):
30+
var = None
31+
try:
32+
var = environ[key]
33+
except KeyError:
34+
pass
35+
if var == '':
36+
var = None
37+
return var
38+
2939
if __name__ == '__main__':
3040
args = parse_arguments()
31-
workspaces = get_workspaces(dict(os.environ))
41+
environment_variables = dict(os.environ)
42+
workspaces = get_workspaces(environment_variables)
3243
if args.maven_deployment_repository:
33-
# assuming one value exists here
34-
print os.path.join(workspaces[0], 'share', 'maven')
44+
repo = get_environment_variable(environment_variables, 'ROS_MAVEN_DEPLOYMENT_REPOSITORY')
45+
if repo is None:
46+
repo = os.path.join(workspaces[0], 'share', 'maven')
47+
else:
48+
if repo in [os.path.join(w, 'share', 'maven') for w in workspaces]:
49+
repo = os.path.join(workspaces[0], 'share', 'maven')
50+
print repo
3551
elif args.maven_path:
36-
maven_repository_paths = [os.path.join(path, 'share', 'maven') for path in workspaces]
37-
print os.pathsep.join(maven_repository_paths)
52+
new_maven_paths = [os.path.join(path, 'share', 'maven') for path in workspaces]
53+
maven_paths = get_environment_variable(environment_variables, 'ROS_MAVEN_PATH')
54+
if maven_paths is None:
55+
maven_paths = new_maven_paths
56+
else:
57+
maven_paths = maven_paths.split(os.pathsep)
58+
common_paths = [p for p in maven_paths if p in new_maven_paths]
59+
if common_paths:
60+
maven_paths = new_maven_paths
61+
print os.pathsep.join(maven_paths)
3862
elif args.gradle_user_home:
39-
# assuming one value exists here
40-
print os.path.join(workspaces[0], 'share', 'gradle')
63+
home = get_environment_variable(environment_variables, 'GRADLE_USER_HOME')
64+
if home is None:
65+
home = os.path.join(workspaces[0], 'share', 'gradle')
66+
else:
67+
if home in [os.path.join(w, 'share', 'gradle') for w in workspaces]:
68+
home = os.path.join(workspaces[0], 'share', 'gradle')
69+
print home
4170
else:
4271
print "Nothing to see here - please provide one of the valid command switches."

0 commit comments

Comments
 (0)