Skip to content

Commit

Permalink
ros2: update env vars for new build/install locations
Browse files Browse the repository at this point in the history
  • Loading branch information
dodsonmg committed Aug 6, 2021
1 parent 7e2ff92 commit d806483
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions pycheribuild/projects/cross/ros2.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,29 +81,14 @@ def clean(self):
def cmake_prefix_paths(self):
return super().cmake_prefix_paths + [self.install_dir]

def _get_poco(self):
# find and copy libPocoFoundation.so.71 from the sysroot into self.source_dir
# this is a bit ugly, but allows us to link the poco library whether we're running
# hybrid or purecap cheribsd. this is helpful because if we're running hybrid cheribsd,
# the hybrid rootfs gets mounted, which doesn't include the purecap build of the poco library.
#
# one day, if we're only running the purecap kernel, we can just append the path
# of libPocoFoundation.so.71 to LD_CHERI_LIBRARY_PATH in _set_env() below.
poco_path = self.target_info.sysroot_install_prefix_absolute / "lib/libPocoUtil.so.71"
if poco_path.is_file():
self.info("Found pocofoundation:", poco_path)
self.install_file(poco_path, self.source_dir / poco_path.name, force=True, print_verbose_only=False)
else:
self.fatal("libPocoFoundation.so.71 cannot be found at expected path", poco_path)

def _set_env(self):
# create cheri_setup.csh and cheri_setup.sh files in self.source_dir which can be source'ed
# to set environment variables (primarily LD_CHERI_LIBRARY_PATH)
#
# based off the install/setup.bash file sourced for ubuntu installs

# source the setup script created by ROS to set LD_LIBRARY_PATH
setup_script = self.source_dir / "install" / "setup.bash"
setup_script = self.install_dir / "setup.bash"
if not setup_script.is_file():
self.warning("No setup.bash file to source.")
return
Expand All @@ -116,9 +101,20 @@ def _set_env(self):
self.warning("LD_LIBRARY_PATH not set.")
return

# add Poco libraries to LD_LIBRARY_PATH
poco_path = self.target_info.sysroot_install_prefix_absolute / "lib"
if (poco_path / "libPocoFoundation.so.71").is_file():
self.info("Found libPocoFoundation.so.71 in the expected path: ", poco_path)
ld_library_path = ld_library_path + ":" + str(poco_path)
else:
self.fatal("libPocoFoundation.so.71 was not found in the expected path: ", poco_path)

# remove the host prefix for the install directory from entries in the
# LD_LIBRARY_PATH
host_prefix = str(self.install_dir).split("/opt")[0]
ld_library_path = ld_library_path.replace(str(host_prefix), "")

# convert LD_LIBRARY_PATH into LD_CHERI_LIBRARY_PATH for CheriBSD
ld_library_path = str(self.source_dir) + ":" + ld_library_path
ld_library_path = ld_library_path.replace(str(self.source_dir), "${rootdir}")
ld_cheri_library_path = ld_library_path
ld_cheri_library_path += ":${LD_CHERI_LIBRARY_PATH}"
ld_library_path += ":${LD_LIBRARY_PATH}"
Expand All @@ -136,14 +132,14 @@ def _set_env(self):
endif
setenv LD_LIBRARY_PATH {LD_LIBRARY_PATH}
""".format(LD_CHERI_LIBRARY_PATH=ld_cheri_library_path, LD_LIBRARY_PATH=ld_library_path)
self.write_file(self.source_dir / 'cheri_setup.csh', csh_script, overwrite=True)
self.write_file(self.install_dir / 'cheri_setup.csh', csh_script, overwrite=True)
posix_sh_script = """#!/bin/sh
rootdir=`pwd`
export LD_CHERI_LIBRARY_PATH={LD_CHERI_LIBRARY_PATH}
export LD_LIBRARY_PATH={LD_LIBRARY_PATH}
""".format(LD_CHERI_LIBRARY_PATH=ld_cheri_library_path, LD_LIBRARY_PATH=ld_library_path)
# write LD_CHERI_LIBRARY_PATH to a text file to source from sh in CheriBSD
self.write_file(self.source_dir / 'cheri_setup.sh', posix_sh_script, overwrite=True)
self.write_file(self.install_dir / 'cheri_setup.sh', posix_sh_script, overwrite=True)

def update(self):
super().update()
Expand All @@ -167,10 +163,12 @@ def install(self, **kwargs):

# call the functions to copy the poco library and create an env setup file
if not self.compiling_for_host():
self._get_poco()
self._set_env()

def run_tests(self):
# only test when not compiling for host
if not self.compiling_for_host():
self.target_info.run_cheribsd_test_script("run_ros2_tests.py", mount_sourcedir=True, mount_sysroot=True)
self.target_info.run_cheribsd_test_script("run_ros2_tests.py",
mount_sourcedir=True,
mount_installdir=True,
mount_sysroot=True)

0 comments on commit d806483

Please sign in to comment.