catkin / catkin_tools

Command line tools for working with catkin
Apache License 2.0
163 stars 146 forks source link

Difference between cached and current CMAKE_PREFIX_PATHS with "@" symbol in it cause catkin init to fail #720

Closed AndreasNagel closed 2 years ago

AndreasNagel commented 2 years ago

System Info

Build / Run Issue

Similar to 521. Calling catkin init or catkin build in a workspace with the name /home/user@lan/catkin_ws fails with a cryptic KeyError, when the cached CMAKE_PREFIX_PATH is different from the current environment one.

Expected Behavior

catkin build reports a warning about current CMAKE_PREFIX_PATH being different from the one in cache.

Actual Behavior

Traceback (most recent call last):  
  File "/usr/bin/catkin", line 33, in <module>  
    sys.exit(load_entry_point('catkin-tools==0.8.5', 'console_scripts', 'catkin')())  
  File "/usr/lib/python3/dist-packages/catkin_tools/commands/catkin.py", line 266, in main  
    catkin_main(sysargs)  
  File "/usr/lib/python3/dist-packages/catkin_tools/commands/catkin.py", line 261, in catkin_main  
    sys.exit(args.main(args) or 0)  
  File "/usr/lib/python3/dist-packages/catkin_tools/verbs/catkin_init/cli.py", line 39, in main  
    ctx = Context.load(opts.workspace, strict=True)  
  File "/usr/lib/python3/dist-packages/catkin_tools/context.py", line 260, in load  
    ctx.load_env()  
  File "/usr/lib/python3/dist-packages/catkin_tools/context.py", line 513, in load_env  
    self.warnings += [clr(  
  File "/usr/lib/python3/dist-packages/catkin_tools/terminal_color.py", line 185, in clr  
    return fmt(key)  
  File "/usr/lib/python3/dist-packages/catkin_tools/terminal_color.py", line 133, in fmt  
    return t.substitute(_ansi) + (ansi('reset') if reset else '')  
  File "/usr/lib/python3.8/string.py", line 126, in substitute  
    return self.pattern.sub(convert, self.template)  
  File "/usr/lib/python3.8/string.py", line 119, in convert  
    return str(mapping[named])  
KeyError: 'lan'  

Steps to Reproduce the Issue

Create a catkin workspace A in a path with "@" symbol in it. Add some trivial package. Build the workspace A. Create catkin workspace B in a path with "@" in it, which extends the workspace A. Add some trivial package to B. Build the workspace B. Source both workspaces. Now building the workspace A again should reproduce the error.

The problem seems to be that the current environment's CMAKE_PREFIX_PATH is different rom the cached CMAKE_PREFIX_PATH and either of them contains a path with "@" symbols in it. Calling sanitize on the cached and new CMAKE_PREFIX_PATH variables here shows the warning and does what I expect it to, but I am unsure if this is a good solution to the issue and whether it may occur elsewhere.