99"""
1010__all__ = ('ArgumentResolver' ,)
1111
12- from typing import Any , Dict , Match , Sequence
12+ from typing import Any , Dict , Match
1313import os
1414import re
1515import shlex
2929class ArgumentResolver :
3030 shell : dockerblade .Shell
3131 files : dockerblade .FileSystem
32- workspaces : Sequence [str ]
3332 context : Dict [str , Any ] = attr .ib (default = None )
3433
3534 def _resolve_arg (self , s : str ) -> str :
@@ -88,10 +87,14 @@ def _find_executable(self, package: str, path: str) -> str:
8887 path_original = path
8988
9089 # look for executable in lib/ directory of workspaces
91- for path_workspace in self .workspaces :
92- path_in_ws = os .path .join (path_workspace , 'lib' , package , path )
93- if self .files .access (path_in_ws , os .X_OK ):
94- return path_in_ws
90+ catkin_find_command = ("catkin_find --first-only --libexec "
91+ f"{ shlex .quote (package )} { shlex .quote (path )} " )
92+ try :
93+ path_in_ws = self .shell .check_output (catkin_find_command )
94+ path_in_ws = path_in_ws .strip ()
95+ return path_in_ws
96+ except dockerblade .CalledProcessError :
97+ pass
9598
9699 # look for executable in source directory of package
97100 path_package = self ._find_package_path (package )
@@ -103,10 +106,15 @@ def _find_executable(self, package: str, path: str) -> str:
103106 return path_in_package
104107
105108 def _find_resource (self , package : str , path : str ) -> str :
106- for path_workspace in self .workspaces :
107- path_in_ws = os .path .join (path_workspace , 'share' , package , path )
108- if self .files .isfile (path_in_ws ):
109- return path_in_ws
109+ catkin_find_command = ("catkin_find --first-only --share "
110+ f"{ shlex .quote (package )} { shlex .quote (path )} " )
111+ try :
112+ path_in_ws = self .shell .check_output (catkin_find_command )
113+ path_in_ws = path_in_ws .strip ()
114+ return path_in_ws
115+ except dockerblade .CalledProcessError :
116+ pass
117+
110118 path_package = self ._find_package_path (package )
111119 path_in_package = os .path .join (path_package , path )
112120 if not self .files .isfile (path_in_package ):
0 commit comments