def main(): # parse command line options #(options, args) = get_options(['rosdistro', 'buildsystem'], ['repeat', 'source-only']) parser = optparse.OptionParser() (options, args) = parser.parse_args() if not options: return -1 platform = args[0] # e.g. precise arch = args[1] # e.g. amd64 email = args[2] # e.g. [email protected] ros_distro = args[3] # e.g. groovy # parse the rosdistro file print "Parsing rosdistro file for %s"%ros_distro distro = rosdistro.RosDistro(ros_distro) print "Parsing devel file for %s"%ros_distro devel = rosdistro.DevelDistro(ros_distro) env = get_environment2() try: for stack in distro.get_repositories(): print 'Analyzing stack %s'%stack h = subprocess.Popen(('run_chroot_jenkins_now %s %s %s metrics %s %s wet'%(platform, arch, email, ros_distro,stack)).split(' '),env=env) h.communicate() except Exception, ex: print "%s. Check the console output for test failure details."%ex traceback.print_exc(file=sys.stdout) raise ex
def _test_repositories_fuerte(ros_distro, repo_list, version_list, workspace, test_depends_on, repo_sourcespace, dependson_sourcespace, repo_buildspace, dependson_buildspace, sudo=False, no_chroot=False): import rosdistro # parse the rosdistro file print "Parsing rosdistro file for %s" % ros_distro distro = rosdistro.RosDistro(ros_distro) print "Parsing devel file for %s" % ros_distro devel = rosdistro.DevelDistro(ros_distro) # Create rosdep object print "Create rosdep object" rosdep_resolver = rosdep.RosDepResolver(ros_distro, sudo, no_chroot) # download the repo_list from source print "Creating rosinstall file for repo list" rosinstall = "" for repo, version in zip(repo_list, version_list): if version == 'devel': if repo not in devel.repositories: raise BuildException("Repository %s does not exist in Devel Distro" % repo) print "Using devel distro file to download repositories" rosinstall += devel.repositories[repo].get_rosinstall() else: if repo not in distro.get_repositories(): raise BuildException("Repository %s does not exist in Ros Distro" % repo) if version in ['latest', 'master']: print "Using latest release distro file to download repositories" rosinstall += distro.get_rosinstall(repo, version='master') else: print "Using version %s of release distro file to download repositories" % version rosinstall += distro.get_rosinstall(repo, version) print "rosinstall file for all repositories: \n %s" % rosinstall with open(os.path.join(workspace, "repo.rosinstall"), 'w') as f: f.write(rosinstall) print "Install repo list from source" os.makedirs(repo_sourcespace) call("rosinstall %s %s/repo.rosinstall --catkin" % (repo_sourcespace, workspace)) # get the repositories build dependencies print "Get build dependencies of repo list" repo_build_dependencies = get_dependencies(repo_sourcespace, build_depends=True, run_depends=False) print "Install build dependencies of repo list: %s" % (', '.join(repo_build_dependencies)) apt_get_install(repo_build_dependencies, rosdep_resolver, sudo) # replace the CMakeLists.txt file for repositories that use catkin print "Removing the CMakeLists.txt file generated by rosinstall" os.remove(os.path.join(repo_sourcespace, 'CMakeLists.txt')) print "Create a new CMakeLists.txt file using catkin" ros_env = get_ros_env('/opt/ros/%s/setup.bash' % ros_distro) call("catkin_init_workspace %s" % repo_sourcespace, ros_env) test_results_dir = os.path.join(workspace, 'test_results') repos_test_results_dir = os.path.join(test_results_dir, 'repos') os.makedirs(repo_buildspace) os.chdir(repo_buildspace) helper = subprocess.Popen(('cmake %s -DCMAKE_TOOLCHAIN_FILE=/opt/ros/groovy/share/ros/core/rosbuild/rostoolchain.cmake -DCATKIN_TEST_RESULTS_DIR=%s'%(repo_sourcespace,repos_test_results_dir)).split(' '), env=ros_env) helper.communicate() res = 0 if helper.returncode != 0: res = helper.returncode ros_env_repo = get_ros_env(os.path.join(repo_buildspace, 'devel/setup.bash')) # build repositories print "Build repo list" print "CMAKE_PREFIX_PATH: %s"%ros_env['CMAKE_PREFIX_PATH'] call("make", ros_env) # Concatenate filelists print '----------------- Concatenate filelists ----------------- ' filelist = '%s'%repo_buildspace + '/filelist.lst' helper = subprocess.Popen(('%s/jenkins_scripts/code_quality/concatenate_filelists.py --dir %s --filelist %s'%(workspace,repo_buildspace, filelist)).split(' '), env=os.environ) helper.communicate() print '////////////////// cma analysis done ////////////////// \n\n' # Run CMA print '----------------- Run CMA analysis ----------------- ' cmaf = repo_sourcespace#repo_buildspace helper = subprocess.Popen(('pal QACPP -cmaf %s -list %s'%(cmaf, filelist)).split(' '), env=os.environ) helper.communicate() print '////////////////// cma analysis done ////////////////// \n\n' # Export metrics to yaml and csv files # get uri infos uri= distro.get_repositories()[repo_list[0]].url uri_info= 'master' vcs_type= 'git' print '----------------- Export metrics to yaml and csv files ----------------- ' helper = subprocess.Popen(('%s/jenkins_scripts/code_quality/wet/export_metrics_to_yaml_wet.py --path %s --path_src %s --doc metrics --csv csv --config %s/jenkins_scripts/code_quality/export_config.yaml --distro %s --stack %s --uri %s --uri_info %s --vcs_type %s'%(workspace, repo_buildspace, repo_sourcespace, workspace, ros_distro, repo_list, uri, uri_info, vcs_type)).split(' '), env=os.environ) helper.communicate() print '////////////////// export metrics to yaml and csv files done ////////////////// \n\n' # Push results to server print '----------------- Push results to server ----------------- ' helper = subprocess.Popen(('%s/jenkins_scripts/code_quality/wet/push_results_to_server_wet.py --path %s --doc metrics --path_src %s --meta_package %s'%(workspace, repo_buildspace, repo_sourcespace, repo_list)).split(' '), env=os.environ) helper.communicate() print '////////////////// push results to server done ////////////////// \n\n' # Upload results to QAVerify print ' ----------------- upload results to QAVerify ----------------- ' shutil.rmtree(os.path.join(workspace, 'snapshots_path'), ignore_errors=True) os.makedirs(os.path.join(workspace, 'snapshots_path')) snapshots_path = '%s/snapshots_path'%workspace project_name = repo_list[0] + '-' + ros_distro helper = subprocess.Popen(('%s/jenkins_scripts/code_quality/wet/upload_to_QAVerify_wet.py --path %s --snapshot %s --project %s --stack_name %s'%(workspace, repo_buildspace, snapshots_path, project_name, repo_list[0])).split(' '), env=os.environ) helper.communicate() print '////////////////// upload results to QAVerify done ////////////////// \n\n' if os.path.exists(snapshots_path): shutil.rmtree(snapshots_path) if res != 0: print "helper_return_code is: %s"%(helper.returncode) assert 'analysis_wet.py failed' raise Exception("analysis_wet.py failed. Check out the console output above for details.") # create dummy test results env = dict() env['INSTALL_DIR'] = os.getenv('INSTALL_DIR', '') test_results_path = workspace + '/test_results' if os.path.exists(test_results_path): shutil.rmtree(test_results_path) os.makedirs(test_results_path) test_file= test_results_path + '/test_file.xml' f = open(test_file, 'w') f.write('<?xml version="1.0" encoding="UTF-8"?>\n') f.write('<testsuite tests="1" failures="0" time="1" errors="0" name="dummy test">\n') f.write(' <testcase name="dummy rapport" classname="Results" /> \n') f.write('</testsuite> \n') f.close()
def _test_repositories_fuerte(ros_distro, repo_list, version_list, workspace, test_depends_on, repo_sourcespace, dependson_sourcespace, repo_buildspace, dependson_buildspace, sudo=False, no_chroot=False): import rosdistro # parse the rosdistro file print "Parsing rosdistro file for %s" % ros_distro distro = rosdistro.RosDistro(ros_distro) print "Parsing devel file for %s" % ros_distro devel = rosdistro.DevelDistro(ros_distro) # Create rosdep object print "Create rosdep object" rosdep_resolver = rosdep.RosDepResolver(ros_distro, sudo, no_chroot) # download the repo_list from source print "Creating rosinstall file for repo list" rosinstall = "" for repo, version in zip(repo_list, version_list): if version == 'devel': if repo not in devel.repositories: raise BuildException("Repository %s does not exist in Devel Distro" % repo) print "Using devel distro file to download repositories" rosinstall += devel.repositories[repo].get_rosinstall() else: if repo not in distro.get_repositories(): raise BuildException("Repository %s does not exist in Ros Distro" % repo) if version in ['latest', 'master']: print "Using latest release distro file to download repositories" rosinstall += distro.get_rosinstall(repo, version='master') else: print "Using version %s of release distro file to download repositories" % version rosinstall += distro.get_rosinstall(repo, version) print "rosinstall file for all repositories: \n %s" % rosinstall with open(os.path.join(workspace, "repo.rosinstall"), 'w') as f: f.write(rosinstall) print "Install repo list from source" os.makedirs(repo_sourcespace) call("rosinstall %s %s/repo.rosinstall --catkin" % (repo_sourcespace, workspace)) # get the repositories build dependencies print "Get build dependencies of repo list" repo_build_dependencies = get_dependencies(repo_sourcespace, build_depends=True, test_depends=False) print "Install build dependencies of repo list: %s" % (', '.join(repo_build_dependencies)) apt_get_install(repo_build_dependencies, rosdep_resolver, sudo) # replace the CMakeLists.txt file for repositories that use catkin print "Removing the CMakeLists.txt file generated by rosinstall" os.remove(os.path.join(repo_sourcespace, 'CMakeLists.txt')) print "Create a new CMakeLists.txt file using catkin" ros_env = get_ros_env('/opt/ros/%s/setup.bash' % ros_distro) call("catkin_init_workspace %s" % repo_sourcespace, ros_env) test_results_dir = os.path.join(workspace, 'test_results') repos_test_results_dir = os.path.join(test_results_dir, 'repos') os.makedirs(repo_buildspace) os.chdir(repo_buildspace) call("cmake %s -DCATKIN_TEST_RESULTS_DIR=%s" % (repo_sourcespace, repos_test_results_dir), ros_env) #ros_env_repo = get_ros_env(os.path.join(repo_buildspace, 'devel/setup.bash')) # build repositories and tests print "Build repo list" call("make", ros_env) call("make tests", ros_env) # get the repositories test and run dependencies print "Get test and run dependencies of repo list" repo_test_dependencies = get_dependencies(repo_sourcespace, build_depends=False, test_depends=True) print "Install test and run dependencies of repo list: %s" % (', '.join(repo_test_dependencies)) apt_get_install(repo_test_dependencies, rosdep_resolver, sudo) # run tests print "Test repo list" call("make run_tests", ros_env) # see if we need to do more work or not if not test_depends_on: print "We're not testing the depends-on repositories" ensure_test_results(test_results_dir) return # get repo_list depends-on list print "Get list of wet repositories that build-depend on repo list %s" % ', '.join(repo_list) depends_on = [] try: for d in distro.get_depends_on(repo_list)['build'] + distro.get_depends_on(repo_list)['buildtool']: if not d in depends_on and not d in repo_list: depends_on.append(d) except RuntimeError: print "Exception %s: If you are not in the rosdistro and only in the devel", \ " builds there will be no depends on" depends_on = [] print "Build depends_on list of repo list: %s" % (', '.join(depends_on)) if len(depends_on) == 0: print "No wet repositories depend on our repo list. Test finished here" ensure_test_results(test_results_dir) return # install depends_on repositories from source rosinstall = distro.get_rosinstall(depends_on) print "Rosinstall for depends_on:\n %s" % rosinstall with open(workspace + "/depends_on.rosinstall", 'w') as f: f.write(rosinstall) print "Created rosinstall file for depends on" # install all repository and system dependencies of the depends_on list print "Install all depends_on from source: %s" % (', '.join(depends_on)) os.makedirs(dependson_sourcespace) call("rosinstall --catkin %s %s/depends_on.rosinstall" % (dependson_sourcespace, workspace)) # get build and test dependencies of depends_on list dependson_build_dependencies = [] for d in get_dependencies(dependson_sourcespace, build_depends=True, test_depends=False): print " Checking dependency %s" % d if d in dependson_build_dependencies: print " Already in dependson_build_dependencies" if d in depends_on: print " Is a direct dependency of the repo list, and is installed from source" if d in repo_list: print " Is on of the repositories tested" if not d in dependson_build_dependencies and not d in depends_on and not d in repo_list: dependson_build_dependencies.append(d) print "Build dependencies of depends_on list are %s" % (', '.join(dependson_build_dependencies)) dependson_test_dependencies = [] for d in get_dependencies(dependson_sourcespace, build_depends=False, test_depends=True): if not d in dependson_test_dependencies and not d in depends_on and not d in repo_list: dependson_test_dependencies.append(d) print "Test dependencies of depends_on list are %s" % (', '.join(dependson_test_dependencies)) # install build dependencies print "Install all build dependencies of the depends_on list" apt_get_install(dependson_build_dependencies, rosdep_resolver, sudo) # replace the CMakeLists.txt file again print "Removing the CMakeLists.txt file generated by rosinstall" os.remove(os.path.join(dependson_sourcespace, 'CMakeLists.txt')) os.makedirs(dependson_buildspace) os.chdir(dependson_buildspace) print "Create a new CMakeLists.txt file using catkin" call("catkin_init_workspace %s" % dependson_sourcespace, ros_env) depends_on_test_results_dir = os.path.join(test_results_dir, 'depends_on') call("cmake %s -DCATKIN_TEST_RESULTS_DIR=%s" % (dependson_sourcespace, depends_on_test_results_dir), ros_env) #ros_env_depends_on = get_ros_env(os.path.join(dependson_buildspace, 'devel/setup.bash')) # build repositories print "Build depends-on repositories" call("make", ros_env) # install test dependencies print "Install all test dependencies of the depends_on list" apt_get_install(dependson_test_dependencies, rosdep_resolver, sudo) # test repositories print "Test depends-on repositories" call("make run_tests", ros_env) ensure_test_results(test_results_dir)