Package rosmake :: Module package_stats
[frames] | no frames]

Source Code for Module rosmake.package_stats

  1  #! /usr/bin/env python 
  2   
  3  # Copyright (c) 2009, Willow Garage, Inc. 
  4  # All rights reserved. 
  5  #  
  6  # Redistribution and use in source and binary forms, with or without 
  7  # modification, are permitted provided that the following conditions are met: 
  8  #  
  9  #     * Redistributions of source code must retain the above copyright 
 10  #       notice, this list of conditions and the following disclaimer. 
 11  #     * Redistributions in binary form must reproduce the above copyright 
 12  #       notice, this list of conditions and the following disclaimer in the 
 13  #       documentation and/or other materials provided with the distribution. 
 14  #     * Neither the name of Willow Garage, Inc. nor the names of its 
 15  #       contributors may be used to endorse or promote products derived from 
 16  #       this software without specific prior written permission. 
 17  #  
 18  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 19  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 20  # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 21  # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 22  # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 23  # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 24  # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
 25  # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 26  # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 27  # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 28  # POSSIBILITY OF SUCH DAMAGE. 
 29   
 30   
 31  # Author Tully Foote/tfoote@willowgarage.com 
 32   
 33  import os 
 34  import sys 
 35  import subprocess 
 36   
 37  import rospkg 
 38  import rospkg.os_detect 
 39   
40 -def _platform_supported(m, os, version):
41 for p in m.platforms: 42 if os == p.os and version == p.version: 43 return True 44 return False
45
46 -def platform_supported(rospack, pkg, os, version):
47 """ 48 Return whether the platform defined by os and version is marked as supported in the package 49 @param pkg The package to test for support 50 @param os The os name to test for support 51 @param version The os version to test for support 52 """ 53 return _platform_supported(rospack.get_manifest(pkg), os, version)
54
55 -class PackageFlagTracker:
56 """ This will use the dependency tracker to test if packages are 57 blacklisted and all their dependents. """
58 - def __init__(self, dependency_tracker, os_name = None, os_version = None):
59 if not os_name and not os_version: 60 try: 61 osd = rospkg.os_detect.OsDetect() 62 self.os_name = osd.get_codename() 63 self.os_version = osd.get_version() 64 except rospkg.os_detect.OsNotDetected as ex: 65 sys.stderr.write("Could not detect OS. platform detection will not work\n") 66 else: 67 self.os_name = os_name 68 self.os_version = os_version 69 70 self.rospack = rospkg.RosPack() 71 self.blacklisted = {} 72 self.blacklisted_osx = {} 73 self.nobuild = set() 74 self.nomakefile = set() 75 self.packages_tested = set() 76 self.dependency_tracker = dependency_tracker 77 self.build_failed = set()
78
79 - def register_blacklisted(self, blacklisted_package, dependent_package):
80 if dependent_package in self.blacklisted.keys(): 81 self.blacklisted[dependent_package].append(blacklisted_package) 82 else: 83 self.blacklisted[dependent_package] = [blacklisted_package]
84
85 - def register_blacklisted_osx(self, blacklisted_package, dependent_package):
86 if dependent_package in self.blacklisted_osx: 87 self.blacklisted_osx[dependent_package].append(blacklisted_package) 88 else: 89 self.blacklisted_osx[dependent_package] = [blacklisted_package]
90
91 - def _check_package_flags(self, package):
92 if package in self.packages_tested: 93 return 94 rospack = self.rospack 95 path = rospack.get_path(package) 96 97 if os.path.exists(os.path.join(path, "ROS_BUILD_BLACKLIST")): 98 self.register_blacklisted(package, package) 99 for p in rospack.get_depends_on(package, implicit=True): 100 self.register_blacklisted(package, p) 101 102 if os.path.exists(os.path.join(path, "ROS_BUILD_BLACKLIST_OSX")): 103 self.register_blacklisted_osx(package, package) 104 for p in rospack.get_depends_on(package, implicit=True): 105 self.register_blacklisted_osx(package, p) 106 107 # NO_BUILD if marker file or catkin attribute in manifest 108 if os.path.exists(os.path.join(path, "ROS_NOBUILD")): 109 self.nobuild.add(package) 110 if self.rospack.get_manifest(package).is_catkin: 111 self.nobuild.add(package) 112 113 if not os.path.exists(os.path.join(path, "Makefile")): 114 self.nomakefile.add(package) 115 116 self.packages_tested.add(package)
117
118 - def is_blacklisted(self, package):
119 # this will noop if already run 120 self._check_package_flags(package) 121 122 # make sure it's not dependent on a blacklisted package 123 for p in self.dependency_tracker.get_deps(package): 124 if p not in self.packages_tested: 125 self._check_package_flags(p) 126 127 # test result after checking all dependents. 128 if package in self.blacklisted: 129 return self.blacklisted[package] 130 131 return []
132
133 - def is_blacklisted_osx(self, package):
134 # this will noop if already run 135 self._check_package_flags(package) 136 137 # make sure it's not dependent on a blacklisted_osx package 138 for p in self.dependency_tracker.get_deps(package): 139 if p not in self.packages_tested: 140 self._check_package_flags(p) 141 142 # test result after checking all dependents. 143 if package in self.blacklisted_osx: 144 return self.blacklisted_osx[package] 145 146 return []
147
148 - def has_nobuild(self, package):
149 # this will noop if already run 150 self._check_package_flags(package) 151 152 # Short circuit if known result 153 if package in self.nobuild: 154 return True 155 return False
156
157 - def has_makefile(self, package):
158 # this will noop if already run 159 self._check_package_flags(package) 160 161 # Short circuit if known result 162 if package in self.nomakefile: 163 return False 164 return True
165
166 - def add_nobuild(self, package):
167 if self.has_nobuild(package): 168 return True 169 with open(os.path.join(self.rospack.get_path(package), "ROS_NOBUILD"), 'w') as f: 170 f.write("created by rosmake to mark as installed") 171 self.nobuild.add(package) 172 return True 173 return False
174
175 - def remove_nobuild(self, package):
176 if not self.has_nobuild(package): 177 return True 178 try: 179 os.remove(os.path.join(self.rospack.get_path(package), "ROS_NOBUILD")) 180 self.nobuild.remove(package) 181 return True 182 except: 183 return False
184
185 - def mark_build_failed(self, package):
186 self.build_failed.add(package)
187
188 - def build_failed(self, package):
189 return package in self.build_failed
190
191 - def can_build(self, pkg, use_blacklist = False, failed_packages = [], use_makefile = True):
192 """ 193 Return (buildable, error, "reason why not") 194 """ 195 output_str = "" 196 output_state = True 197 buildable = True 198 199 previously_failed_pkgs = [ pk for pk in failed_packages if pk in self.dependency_tracker.get_deps(pkg)] 200 if len(previously_failed_pkgs) > 0: 201 buildable = False 202 output_state = False 203 output_str += " Package %s cannot be built for dependent package(s) %s failed. \n"%(pkg, previously_failed_pkgs) 204 205 206 if use_blacklist: 207 black_listed_dependents = self.is_blacklisted(pkg) 208 if len(black_listed_dependents) > 0: 209 buildable = False 210 output_str += "Cannot build %s ROS_BUILD_BLACKLIST found in packages %s"%(pkg, black_listed_dependents) 211 212 if self.has_nobuild(pkg): 213 buildable = False 214 output_state = True # dependents are ok, it should already be built 215 output_str += "ROS_NOBUILD in package %s\n"%pkg 216 217 218 if use_makefile and not self.has_makefile(pkg): 219 output_state = True # dependents are ok no need to build 220 buildable = False 221 output_str += " No Makefile in package %s\n"%pkg 222 223 if output_str and output_str[-1] == '\n': 224 output_str = output_str[:-1] 225 226 return (buildable, output_state, output_str)
227