00001
00002
00003 DEPENDS_ON_DIR = 'depends_on_overlay'
00004
00005
00006 import roslib; roslib.load_manifest("job_generation")
00007 from roslib import stack_manifest
00008 import rosdistro
00009 from jobs_common import *
00010 import sys
00011 import os
00012 import optparse
00013 import subprocess
00014
00015
00016 def main():
00017
00018 (options, args) = get_options(['rosdistro', 'stack'], [])
00019 if not options:
00020 return -1
00021 if len(options.stack) > 1:
00022 print "You can only provide one stack at a time"
00023 return -1
00024 options.stack = options.stack[0]
00025
00026
00027 env = get_environment()
00028 env['ROS_PACKAGE_PATH'] = '%s:%s:/opt/ros/%s/stacks'%(env['WORKSPACE']+'/'+options.stack,
00029 env['INSTALL_DIR']+'/'+DEPENDS_ON_DIR,
00030 options.rosdistro)
00031 if options.stack == 'ros':
00032 env['ROS_ROOT'] = env['WORKSPACE']+'/'+options.stack
00033 print "We're building ROS, so setting the ROS_ROOT to %s"%(env['ROS_ROOT'])
00034 else:
00035 env['ROS_ROOT'] = '/opt/ros/%s/ros'%options.rosdistro
00036 env['PYTHONPATH'] = env['ROS_ROOT']+'/core/roslib/src'
00037 env['PATH'] = '/opt/ros/%s/ros/bin:%s'%(options.rosdistro, os.environ['PATH'])
00038
00039
00040
00041 rosdistro_obj = rosdistro.Distro(get_rosdistro_file(options.rosdistro))
00042 print 'Operating on ROS distro %s'%rosdistro_obj.release_name
00043
00044
00045
00046 print 'Installing debian packages of stack dependencies'
00047 call('sudo apt-get update', env)
00048 with open('%s/%s/stack.xml'%(os.environ['WORKSPACE'], options.stack)) as stack_file:
00049 depends = stack_manifest.parse(stack_file.read()).depends
00050 if len(depends) != 0:
00051 call('sudo apt-get install %s --yes'%(stacks_to_debs(depends, options.rosdistro)), env,
00052 'Installing dependencies of stack "%s": %s'%(options.stack, str(depends)))
00053
00054
00055
00056 print 'Installing system dependencies'
00057 call('rosmake rosdep', env)
00058 call('rosdep install -y %s'%options.stack, env,
00059 'Installing system dependencies of stack %s'%options.stack)
00060
00061
00062
00063 print 'Running Hudson Helper'
00064 env['ROS_TEST_RESULTS_DIR'] = os.environ['ROS_TEST_RESULTS_DIR'] + '/' + options.stack
00065 helper = subprocess.Popen(('./hudson_helper --dir-test %s/%s build'%(env['WORKSPACE'], options.stack)).split(' '), env=env)
00066 helper.communicate()
00067 if helper.returncode != 0:
00068 return helper.returncode
00069
00070
00071
00072 print 'Installing all released stacks of ros distro %s: %s'%(options.rosdistro, str(rosdistro_obj.released_stacks.keys()))
00073 for stack in rosdistro_obj.released_stacks:
00074 call('sudo apt-get install %s --yes'%(stack_to_deb(stack, options.rosdistro)), env, ignore_fail=True)
00075
00076
00077
00078
00079
00080 print 'Installing all stacks that depend on these stacks from source'
00081 res = call('rosstack depends-on %s'%options.stack, env, 'Getting list of stacks that depends on %s'%options.stack)
00082 print 'These stacks depend on the stacks we are testing: "%s"'%str(res)
00083 if res == '':
00084 print 'No stack depends on %s, finishing test.'%options.stack
00085 return 0
00086 rosinstall = stacks_to_rosinstall(res.split('\n'), rosdistro_obj.released_stacks, 'release-tar')
00087 print 'Running rosinstall on "%s"'%rosinstall
00088 rosinstall_file = '%s.rosinstall'%DEPENDS_ON_DIR
00089 with open(rosinstall_file, 'w') as f:
00090 f.write(rosinstall)
00091 call('rosinstall --rosdep-yes %s /opt/ros/%s %s/%s %s'%(DEPENDS_ON_DIR, options.rosdistro, os.environ['WORKSPACE'], options.stack, rosinstall_file), env,
00092 'Install of stacks that depend on %s from source'%options.stack)
00093
00094
00095 print 'Removing all stack from Debian that depend on this stack'
00096 call('sudo apt-get remove %s --yes'%stack_to_deb(options.stack, options.rosdistro), env)
00097
00098
00099
00100 print 'Running Hudson Helper'
00101 env['ROS_TEST_RESULTS_DIR'] = os.environ['ROS_TEST_RESULTS_DIR'] + '/' + DEPENDS_ON_DIR
00102 helper = subprocess.Popen(('./hudson_helper --dir-test %s build'%DEPENDS_ON_DIR).split(' '), env=env)
00103 helper.communicate()
00104 return helper.returncode
00105
00106
00107 if __name__ == '__main__':
00108 try:
00109 res = main()
00110 sys.exit( res )
00111 except Exception:
00112 sys.exit(-1)
00113
00114
00115
00116
00117
00118