def which_executable(env_var, executable_names): env_value = os.getenv(env_var) if env_value: executable = which(env_value) if executable: return executable for executable_name in executable_names: executable = which(executable_name) if executable: return executable return None
def perform(self, context: LaunchContext) -> Text: """Perform the substitution by locating the executable on the PATH.""" from ..utilities import perform_substitutions # import here to avoid loop result = which(perform_substitutions(context, self.name)) if result is None: raise SubstitutionFailure( "executable '{}' not found on the PATH".format(self.name)) return result
def perform(self, context: LaunchContext) -> Text: """Perform the substitution by locating the executable.""" executable = perform_substitutions(context, self.executable) package = perform_substitutions(context, self.package) package_prefix = super().perform(context) package_libexec = os.path.join(package_prefix, 'lib', package) if not os.path.exists(package_libexec): raise SubstitutionFailure( "package '{}' found at '{}', but libexec directory '{}' does not exist" .format(package, package_prefix, package_libexec)) result = which(executable, path=package_libexec) if result is None: raise SubstitutionFailure( "executable '{}' not found on the libexec directory '{}' ". format(executable, package_libexec)) return result
# # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import os import re import subprocess from osrf_pycommon.process_utils import which CMAKE_EXECUTABLE = which('cmake') CTEST_EXECUTABLE = which('ctest') MAKE_EXECUTABLE = which('make') MSBUILD_EXECUTABLE = which('msbuild') NINJA_EXECUTABLE = which('ninja') __target_re = re.compile(r'^([a-zA-Z0-9][a-zA-Z0-9_\.]*):') def has_make_target(path, target): global __target_re output = subprocess.check_output([MAKE_EXECUTABLE, '-pn'], cwd=path) lines = output.decode().splitlines() targets = [m.group(1) for m in [__target_re.match(l) for l in lines] if m] return target in targets
# # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import os import re import subprocess from osrf_pycommon.process_utils import which CMAKE_EXECUTABLE = which('cmake') MAKE_EXECUTABLE = which('make') MSBUILD_EXECUTABLE = which('msbuild') __target_re = re.compile(r'^([a-zA-Z0-9][a-zA-Z0-9_\.]*):') def has_make_target(path, target): global __target_re output = subprocess.check_output([MAKE_EXECUTABLE, '-pn'], cwd=path) lines = output.decode().splitlines() targets = [m.group(1) for m in [__target_re.match(l) for l in lines] if m] return target in targets def cmakecache_exists_at(path):
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import subprocess from ament_tools.build_type import BuildAction from ament_tools.build_type import BuildType from ament_tools.context import ContextExtender from ament_tools.helper import extract_argument_group from osrf_pycommon.process_utils import which BAZEL_EXECUTABLE = which('bazel') def _has_target(path, target): # To query bazel for a list of all labels, we use: # bazel query '//...' --output=label cmd = [BAZEL_EXECUTABLE, 'query', '//...', '--output=label'] output = subprocess.check_output(cmd, cwd=path) lines = output.decode().splitlines() # Each line in the output starts with a double slash, followed by # either a colon and a target name, or a package name. We look to see # if the requested target exists. return target in lines class BazelBuildType(BuildType):
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import subprocess from ament_tools.build_type import BuildAction from ament_tools.build_type import BuildType from ament_tools.context import ContextExtender from ament_tools.helper import extract_argument_group from osrf_pycommon.process_utils import which BAZEL_EXECUTABLE = which('bazel') def _has_target(path, target): # To query bazel for a list of all labels, we use: # bazel query '//...' --output=label cmd = [BAZEL_EXECUTABLE, 'query', '//...', '--output=label'] output = subprocess.check_output(cmd, cwd=path) lines = output.decode().splitlines() # Each line in the output starts with a double slash, followed by # either a colon and a target name, or a package name. We look to see # if the requested target exists. return target in lines class BazelBuildType(BuildType):
# # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import os import re import subprocess from osrf_pycommon.process_utils import which CMAKE_EXECUTABLE = which('cmake') CTEST_EXECUTABLE = which('ctest') MAKE_EXECUTABLE = which('make') MSBUILD_EXECUTABLE = which('msbuild') __target_re = re.compile(r'^([a-zA-Z0-9][a-zA-Z0-9_\.]*):') def has_make_target(path, target): global __target_re output = subprocess.check_output([MAKE_EXECUTABLE, '-pn'], cwd=path) lines = output.decode().splitlines() targets = [m.group(1) for m in [__target_re.match(l) for l in lines] if m] return target in targets
def which_executable(env_var, executable_names): env_value = os.getenv(env_var) if env_value: executable = which(env_value) if executable: return executable for executable_name in executable_names: executable = which(executable_name) if executable: return executable return None CMAKE_EXECUTABLE = which_executable(CMAKE_EXECUTABLE_ENV, ['cmake3', 'cmake']) CTEST_EXECUTABLE = which_executable(CTEST_EXECUTABLE_ENV, ['ctest3', 'ctest']) MAKE_EXECUTABLE = which('make') MSBUILD_EXECUTABLE = which('msbuild') NINJA_EXECUTABLE = which('ninja') XCODEBUILD_EXECUTABLE = which('xcodebuild') __target_re = re.compile(r'^([a-zA-Z0-9][a-zA-Z0-9_\.]*):') def has_make_target(path, target): global __target_re output = subprocess.check_output([MAKE_EXECUTABLE, '-pn'], cwd=path) lines = output.decode().splitlines() targets = [m.group(1) for m in [__target_re.match(l) for l in lines] if m] return target in targets