1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 import os
34 import sys
35 import subprocess
36
37 import rospkg
38 import rospkg.os_detect
39
45
54
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
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
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
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
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
119
120 self._check_package_flags(package)
121
122
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
128 if package in self.blacklisted:
129 return self.blacklisted[package]
130
131 return []
132
134
135 self._check_package_flags(package)
136
137
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
143 if package in self.blacklisted_osx:
144 return self.blacklisted_osx[package]
145
146 return []
147
149
150 self._check_package_flags(package)
151
152
153 if package in self.nobuild:
154 return True
155 return False
156
158
159 self._check_package_flags(package)
160
161
162 if package in self.nomakefile:
163 return False
164 return True
165
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
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
187
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
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
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