00001
00002
00003 from roslib import stack_manifest
00004 from jobs_common import *
00005 from apt_parser import parse_apt
00006 import sys
00007 import os
00008 import optparse
00009 import subprocess
00010 import traceback
00011
00012
00013 def main():
00014
00015 try:
00016 print "Starting run_auto_stack_devel script"
00017
00018
00019 print "Parsing command line options"
00020 (options, args) = get_options(['stack', 'rosdistro'], ['repeat', 'source-only'])
00021 if not options:
00022 return -1
00023 if len(options.stack) > 1:
00024 print "You can only provide one stack at a time"
00025 return -1
00026 options.stack = options.stack[0]
00027 print "parsed options: %s"%str(options)
00028
00029
00030 print "Setting up environment"
00031 env = get_environment()
00032 if options.source_only or options.stack == 'ros':
00033 ros_path = env['WORKSPACE']
00034 else:
00035 ros_path = '/opt/ros/%s'%options.rosdistro
00036 print "Working in %s"%ros_path
00037 env['ROS_PACKAGE_PATH'] = '%s:%s'%(env['WORKSPACE'], ros_path)
00038 env['ROS_ROOT'] = '%s/ros'%ros_path
00039 env['PYTHONPATH'] = env['ROS_ROOT']+'/core/roslib/src'
00040 env['PATH'] = '%s/ros/bin:%s'%(ros_path, os.getenv('PATH'))
00041 stack_dir = env['WORKSPACE']+'/'+options.stack
00042 print("Environment set to %s"%str(env))
00043
00044
00045 rosdistro_obj = rosdistro.Distro(get_rosdistro_file(options.rosdistro))
00046 print 'Operating on ROS distro %s'%rosdistro_obj.release_name
00047
00048
00049 depends = []
00050 stack_xml = '%s/stack.xml'%stack_dir
00051 call('ls %s'%stack_xml, env, 'Checking if stack %s contains "stack.xml" file'%options.stack)
00052 with open(stack_xml) as stack_file:
00053 depends_one = [str(d) for d in stack_manifest.parse(stack_file.read()).depends]
00054 print 'Dependencies of stack %s: %s'%(options.stack, str(depends_one))
00055 for d in depends_one:
00056 if not d == options.stack and not d in depends:
00057 print 'Adding dependencies of stack %s'%d
00058 get_depends_all(rosdistro_obj, d, depends)
00059 print 'Resulting total dependencies: %s'%str(depends)
00060
00061 if len(depends) > 0:
00062 if not options.source_only:
00063
00064 (arch, ubuntudistro) = get_sys_info()
00065 print "Parsing apt repository configuration file to get stack dependencies, for %s machine running %s"%(arch, ubuntudistro)
00066 apt_deps = parse_apt(ubuntudistro, arch, options.rosdistro)
00067 for d in depends:
00068 if not apt_deps.has_debian_package(d):
00069 print "Stack %s does not have Debian package yet. Stopping this test." %d
00070 generate_email("Stack %s does not have Debian package yet. Stopping this test."%d, env)
00071 return 0
00072
00073
00074 print 'Installing debian packages of stack dependencies from stacks %s'%str(options.stack)
00075 call('sudo apt-get update', env)
00076 print 'Installing debian packages of "%s" dependencies: %s'%(options.stack, str(depends))
00077 call('sudo apt-get install %s --yes'%(stacks_to_debs(depends, options.rosdistro)), env)
00078 else:
00079
00080 print 'Installing stack dependencies from source'
00081 rosinstall = stacks_to_rosinstall(depends, rosdistro_obj.released_stacks, 'release-tar')
00082 print 'Using rosinstall yaml: %s'%rosinstall
00083 rosinstall_file = '%s.rosinstall'%options.stack
00084 with open(rosinstall_file, 'w') as f:
00085 f.write(rosinstall)
00086 call('rosinstall --delete-changed-uris --rosdep-yes %s %s'%(env['WORKSPACE'], rosinstall_file), env,
00087 'Install the stack dependencies from source.')
00088 else:
00089 print 'Stack %s does not have any dependencies, not installing anything now'%str(options.stack)
00090
00091
00092 print 'Installing system dependencies of stack %s'%options.stack
00093 call('rosmake rosdep', env)
00094 call('rosdep install -y %s'%options.stack, env,
00095 'Install system dependencies of stack %s'%options.stack)
00096
00097
00098 print 'Running Hudson Helper in folder %s'%stack_dir
00099 res = 0
00100 test_results = env['ROS_TEST_RESULTS_DIR']
00101 for r in range(0, options.repeat+1):
00102 env['ROS_TEST_RESULTS_DIR'] = test_results + '/run_'+str(r)
00103
00104 res_one = subprocess.call(('./hudson_helper --pkg-test %s build'%options.stack).split(' '), env=env)
00105 if res_one != 0:
00106 res = res_one
00107 return res
00108
00109
00110 except Exception, ex:
00111 print "Global exception caught. Generating email with exception text %s"%str(ex)
00112 generate_email("%s. Check the console output for test failure details."%str(ex), env)
00113 traceback.print_exc(file=sys.stdout)
00114 raise ex
00115
00116
00117 if __name__ == '__main__':
00118 try:
00119 res = main()
00120 sys.exit( res )
00121 except Exception, ex:
00122 sys.exit(-1)
00123
00124
00125
00126