rosmake: get rid of call to rospack, more efficient use of rospkg

This commit is contained in:
Ken Conley 2012-03-08 20:17:02 +00:00
parent d65c89e901
commit b92eccabc5
3 changed files with 23 additions and 19 deletions

View File

@ -36,6 +36,7 @@ import sys
import subprocess import subprocess
import threading import threading
import rospkg
import rosmake import rosmake
## make sure that rospack is built, it is a requirement for rosmake ## make sure that rospack is built, it is a requirement for rosmake
@ -44,14 +45,17 @@ def assert_rospack_built():
output = p.communicate() output = p.communicate()
if p.returncode != 0: if p.returncode != 0:
print("rospack not available.\nPlease install rospack before using rosmake and make sure it is available on your path. %s %s"%(output[0], output[1]), file=sys.stderr) print("rospack not available.\nPlease install rospack before using rosmake and make sure it is available on your path. %s %s"%(output[0], output[1]), file=sys.stderr)
sys.exit(-1) sys.exit(1)
result = 1 result = 1
with rosmake.Printer(): with rosmake.Printer():
rma = rosmake.RosMakeAll() rma = rosmake.RosMakeAll()
try:
if rma.main(): if rma.main():
result = 0 result = 0
except rospkg.ResourceNotFound as e:
print("cannot find required resource: %s"%(str(e)))
#make sure the thread is done #make sure the thread is done
rosmake.Printer().join() rosmake.Printer().join()

View File

@ -277,10 +277,14 @@ class Printer:
class RosMakeAll: class RosMakeAll:
def __init__(self): def __init__(self):
self._result_lock = threading.Lock() self._result_lock = threading.Lock()
self.rospack = rospkg.RosPack()
self.rosstack = rospkg.RosStack()
self.printer = Printer() self.printer = Printer()
self.result = {} self.result = {}
self.paths = {} self.paths = {}
self.dependency_tracker = parallel_build.DependencyTracker() self.dependency_tracker = parallel_build.DependencyTracker(rospack=self.rospack)
self.flag_tracker = package_stats.PackageFlagTracker(self.dependency_tracker) self.flag_tracker = package_stats.PackageFlagTracker(self.dependency_tracker)
self.output = {} self.output = {}
self.profile = {} self.profile = {}
@ -629,16 +633,10 @@ class RosMakeAll:
options, args = parser.parse_args() options, args = parser.parse_args()
self.printer.print_all('rosmake starting...')
# TODO: retest whther this logic is necessary now that we are using rospkg rospack = self.rospack
# force a rebuild of the package cache at the top rosstack = self.rosstack
cmd = ["rospack", "profile"]
command_line = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
(pstd_out, pstd_err) = command_line.communicate() # pstd_err should be None due to pipe above
# above is necessary for "roscreate-pkg foo && rosmake foo" to work
self.rospack = rospack = rospkg.RosPack()
self.rosstack = rosstack = rospkg.RosStack()
testing = False testing = False
building = True building = True
@ -708,7 +706,6 @@ class RosMakeAll:
self.printer.print_all( "Packages requested are: %s"%packages) self.printer.print_all( "Packages requested are: %s"%packages)
# Setup logging # Setup logging
if self.logging_enabled: if self.logging_enabled:
date_time_stamp = "rosmake_output-" + time.strftime("%Y%m%d-%H%M%S") date_time_stamp = "rosmake_output-" + time.strftime("%Y%m%d-%H%M%S")
@ -778,13 +775,13 @@ class RosMakeAll:
for pkg in self.build_list: for pkg in self.build_list:
if pkg in self.specified_packages: if pkg in self.specified_packages:
new_list.append(pkg) new_list.append(pkg)
self.dependency_tracker = parallel_build.DependencyTracker(self.specified_packages) # this will make the tracker only respond to packages in the list self.dependency_tracker = parallel_build.DependencyTracker(self.specified_packages, rospack=self.rospack) # this will make the tracker only respond to packages in the list
self.printer.print_all("specified-only option was used, only building packages %s"%new_list) self.printer.print_all("specified-only option was used, only building packages %s"%new_list)
self.build_list = new_list self.build_list = new_list
if options.pre_clean: if options.pre_clean:
build_queue = parallel_build.BuildQueue(self.build_list, parallel_build.DependencyTracker([]), robust_build = True) build_queue = parallel_build.BuildQueue(self.build_list, parallel_build.DependencyTracker([], rospack=self.rospack), robust_build = True)
self.parallel_build_pkgs(build_queue, "clean", threads = options.threads) self.parallel_build_pkgs(build_queue, "clean", threads = options.threads)
build_passed = True build_passed = True
@ -800,7 +797,7 @@ class RosMakeAll:
tests_passed = True tests_passed = True
if build_passed and testing: if build_passed and testing:
self.printer.print_verbose ("Testing packages %s"% packages) self.printer.print_verbose ("Testing packages %s"% packages)
build_queue = parallel_build.BuildQueue(self.specified_packages, parallel_build.DependencyTracker(self.specified_packages), robust_build = True) build_queue = parallel_build.BuildQueue(self.specified_packages, parallel_build.DependencyTracker(self.specified_packages, rospack=self.rospack), robust_build = True)
tests_passed = self.parallel_build_pkgs(build_queue, "test", threads = 1) tests_passed = self.parallel_build_pkgs(build_queue, "test", threads = 1)

View File

@ -79,11 +79,14 @@ class DependencyTracker:
range of packages over which to track dependencies. This is useful range of packages over which to track dependencies. This is useful
if you are only building a subset of the tree. For example with the if you are only building a subset of the tree. For example with the
--specified-only option. """ --specified-only option. """
def __init__(self, valid_packages=None): def __init__(self, valid_packages=None, rospack=None):
""" """
@param valid_packages: defaults to rospack list @param valid_packages: defaults to rospack list
""" """
if rospack is None:
self.rospack = rospkg.RosPack() self.rospack = rospkg.RosPack()
else:
self.rospack = rospack
if valid_packages is None: if valid_packages is None:
valid_packages = self.rospack.list() valid_packages = self.rospack.list()
self.valid_packages = valid_packages self.valid_packages = valid_packages