Exemple #1
0
    def is_compatible(cmd):
        """Check if this subcommand can work with the given command.
        
        Args:
            cmd (str): A command from the command line, e.g. sys.argv[1].

        Returns:
            bool: True if this subcommand is compatible with `cmd`.
        """
        return cmd in [info.command for info in CompilerInfo.all()]
 def __init__(self, absolute_path):
     """Probes the system to find an installed compiler.
     
     May check PATH, file permissions, or other conditions in the system
     to determine if a compiler command is present and executable.
     
     If this compiler command wraps another command, may also attempt to discover
     information about the wrapped compiler as well.
     
     Args:
         absolute_path (str): Absolute path to the compiler command.
     """
     self._md5sum = None
     self.absolute_path = absolute_path
     self.path = os.path.dirname(absolute_path)
     self.command = os.path.basename(absolute_path)
     try:
         self.info = CompilerInfo.find(self.command)
     except KeyError:
         raise RuntimeError("Unknown compiler command '%s'" % self.absolute_path)
     if self.info.family.show_wrapper_flags:
         LOGGER.debug("Probing wrapper compiler '%s' to discover wrapped compiler", self.absolute_path)
         cmd = [self.absolute_path] + self.info.family.show_wrapper_flags
         LOGGER.debug("Creating subprocess: %s", cmd)
         try:
             stdout = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
         except subprocess.CalledProcessError as err:
             raise RuntimeError("%s failed with return code %d: %s" % (cmd, err.returncode, err.output))
         else:
             LOGGER.debug(stdout)
             LOGGER.debug("%s returned 0", cmd)
         args = stdout.split()
         self.wrapped = WrappedCompiler(args[0])
         try:
             self.wrapped.parse_args(args[1:], self.info.family)
         except IndexError:
             raise RuntimeError("Unexpected output from '%s':\n%s" % (' '.join(cmd), stdout))
     else:
         self.wrapped = None