Skip to content

Commit 71a0804

Browse files
committed
ros2: update env vars for new build/install locations
1 parent 7e2ff92 commit 71a0804

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

pycheribuild/projects/cross/ros2.py

+17-22
Original file line numberDiff line numberDiff line change
@@ -81,29 +81,14 @@ def clean(self):
8181
def cmake_prefix_paths(self):
8282
return super().cmake_prefix_paths + [self.install_dir]
8383

84-
def _get_poco(self):
85-
# find and copy libPocoFoundation.so.71 from the sysroot into self.source_dir
86-
# this is a bit ugly, but allows us to link the poco library whether we're running
87-
# hybrid or purecap cheribsd. this is helpful because if we're running hybrid cheribsd,
88-
# the hybrid rootfs gets mounted, which doesn't include the purecap build of the poco library.
89-
#
90-
# one day, if we're only running the purecap kernel, we can just append the path
91-
# of libPocoFoundation.so.71 to LD_CHERI_LIBRARY_PATH in _set_env() below.
92-
poco_path = self.target_info.sysroot_install_prefix_absolute / "lib/libPocoUtil.so.71"
93-
if poco_path.is_file():
94-
self.info("Found pocofoundation:", poco_path)
95-
self.install_file(poco_path, self.source_dir / poco_path.name, force=True, print_verbose_only=False)
96-
else:
97-
self.fatal("libPocoFoundation.so.71 cannot be found at expected path", poco_path)
98-
9984
def _set_env(self):
10085
# create cheri_setup.csh and cheri_setup.sh files in self.source_dir which can be source'ed
10186
# to set environment variables (primarily LD_CHERI_LIBRARY_PATH)
10287
#
10388
# based off the install/setup.bash file sourced for ubuntu installs
10489

10590
# source the setup script created by ROS to set LD_LIBRARY_PATH
106-
setup_script = self.source_dir / "install" / "setup.bash"
91+
setup_script = self.install_dir / "setup.bash"
10792
if not setup_script.is_file():
10893
self.warning("No setup.bash file to source.")
10994
return
@@ -116,9 +101,20 @@ def _set_env(self):
116101
self.warning("LD_LIBRARY_PATH not set.")
117102
return
118103

104+
# add Poco libraries to LD_LIBRARY_PATH
105+
poco_path = self.target_info.sysroot_install_prefix_absolute / "lib"
106+
if (poco_path / "libPocoFoundation.so.71").is_file():
107+
self.info("Found libPocoFoundation.so.71 in the expected path: ", poco_path)
108+
ld_library_path = ld_library_path + ":" + str(poco_path)
109+
else:
110+
self.fatal("libPocoFoundation.so.71 was not found in the expected path: ", poco_path)
111+
112+
# remove the host prefix for the install directory from entries in the
113+
# LD_LIBRARY_PATH
114+
host_prefix = str(self.install_dir).split("/opt")[0]
115+
ld_library_path = ld_library_path.replace(str(host_prefix), "")
116+
119117
# convert LD_LIBRARY_PATH into LD_CHERI_LIBRARY_PATH for CheriBSD
120-
ld_library_path = str(self.source_dir) + ":" + ld_library_path
121-
ld_library_path = ld_library_path.replace(str(self.source_dir), "${rootdir}")
122118
ld_cheri_library_path = ld_library_path
123119
ld_cheri_library_path += ":${LD_CHERI_LIBRARY_PATH}"
124120
ld_library_path += ":${LD_LIBRARY_PATH}"
@@ -136,14 +132,14 @@ def _set_env(self):
136132
endif
137133
setenv LD_LIBRARY_PATH {LD_LIBRARY_PATH}
138134
""".format(LD_CHERI_LIBRARY_PATH=ld_cheri_library_path, LD_LIBRARY_PATH=ld_library_path)
139-
self.write_file(self.source_dir / 'cheri_setup.csh', csh_script, overwrite=True)
135+
self.write_file(self.install_dir / 'cheri_setup.csh', csh_script, overwrite=True)
140136
posix_sh_script = """#!/bin/sh
141137
rootdir=`pwd`
142138
export LD_CHERI_LIBRARY_PATH={LD_CHERI_LIBRARY_PATH}
143139
export LD_LIBRARY_PATH={LD_LIBRARY_PATH}
144140
""".format(LD_CHERI_LIBRARY_PATH=ld_cheri_library_path, LD_LIBRARY_PATH=ld_library_path)
145141
# write LD_CHERI_LIBRARY_PATH to a text file to source from sh in CheriBSD
146-
self.write_file(self.source_dir / 'cheri_setup.sh', posix_sh_script, overwrite=True)
142+
self.write_file(self.install_dir / 'cheri_setup.sh', posix_sh_script, overwrite=True)
147143

148144
def update(self):
149145
super().update()
@@ -167,10 +163,9 @@ def install(self, **kwargs):
167163

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

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

0 commit comments

Comments
 (0)