@@ -51,12 +51,14 @@ def __init__(self, library_folder, packages_folder, distro):
5151 self .library = self .library_path + "/libmicroros.a"
5252 self .includes = self .library_path + '/include'
5353 self .library_name = "microros"
54+ self .env = {}
5455
5556 def run (self , meta , toolchain , user_meta = "" ):
5657 if os .path .exists (self .library_path ):
5758 print ("micro-ROS already built" )
5859 return
5960
61+ self .check_env ()
6062 self .download_dev_environment ()
6163 self .build_dev_environment ()
6264 self .download_mcu_environment ()
@@ -71,6 +73,16 @@ def ignore_package(self, name):
7173 if p .name == name :
7274 p .ignore ()
7375
76+ def check_env (self ):
77+ ROS_DISTRO = os .getenv ('ROS_DISTRO' )
78+
79+ if (ROS_DISTRO ):
80+ PATH = os .getenv ('PATH' )
81+ os .environ ['PATH' ] = PATH .replace ('/opt/ros/{}/bin:' .format (ROS_DISTRO ), '' )
82+ os .environ .pop ('AMENT_PREFIX_PATH' , None )
83+
84+ self .env = os .environ .copy ()
85+
7486 def download_dev_environment (self ):
7587 shutil .rmtree (self .dev_src_folder , ignore_errors = True )
7688 os .makedirs (self .dev_src_folder )
@@ -83,7 +95,7 @@ def download_dev_environment(self):
8395 def build_dev_environment (self ):
8496 print ("Building micro-ROS dev dependencies" )
8597 command = "cd {} && colcon build --cmake-args -DBUILD_TESTING=OFF" .format (self .dev_folder )
86- result = run_cmd (command )
98+ result = run_cmd (command , env = self . env )
8799
88100 if 0 != result .returncode :
89101 print ("Build dev micro-ROS environment failed: \n {}" .format (result .stderr .decode ("utf-8" )))
@@ -158,7 +170,7 @@ def build_mcu_environment(self, meta_file, toolchain_file, user_meta = ""):
158170 common_meta_path = self .library_folder + '/metas/common.meta'
159171 colcon_command = 'colcon build --merge-install --packages-ignore-regex=.*_cpp --metas {} {} {} --cmake-args -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=OFF -DTHIRDPARTY=ON -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE={}' .format (common_meta_path , meta_file , user_meta , toolchain_file )
160172 command = "cd {} && . {}/install/setup.sh && {}" .format (self .mcu_folder , self .dev_folder , colcon_command )
161- result = run_cmd (command )
173+ result = run_cmd (command , env = self . env )
162174
163175 if 0 != result .returncode :
164176 print ("Build mcu micro-ROS environment failed: \n {}" .format (result .stderr .decode ("utf-8" )))
0 commit comments