| 6 | |
| 7 | |
| 8 | class CMD: |
| 9 | def __init__(self, cmd: str, path: Path = Path()): |
| 10 | self.path = path.absolute() |
| 11 | self.cmd = cmd |
| 12 | |
| 13 | def __str__(self): |
| 14 | return f"CMD[path: {self.path}\n" + f" cmd: {self.cmd}]" |
| 15 | |
| 16 | def is_link(self): |
| 17 | if (" -c " not in self.cmd) and (not self.cmd.endswith("-c")): |
| 18 | return True |
| 19 | return False |
| 20 | |
| 21 | def is_assemble(self): |
| 22 | tool = self.cmd.split()[0] |
| 23 | if "yasm" in tool: |
| 24 | return True |
| 25 | |
| 26 | output = re.search(r"(-o )(.+?)( |$)", self.cmd) |
| 27 | if output is not None and re.search( |
| 28 | r"[\w._/-]+?\.l?(s)", output.group(3) |
| 29 | ): |
| 30 | return True |
| 31 | |
| 32 | tokens = [ |
| 33 | token |
| 34 | for token in self.cmd.split() |
| 35 | if Path(token).exists() and token.endswith(".S") |
| 36 | ] |
| 37 | return True if tokens else False |
| 38 | |
| 39 | def abspath(self, src: Path) -> Path: |
| 40 | if src.is_absolute(): |
| 41 | return src.resolve() |
| 42 | return (self.path / src).resolve() |
| 43 | |
| 44 | def output(self, real: bool = True) -> Path: |
| 45 | result = "" |
| 46 | if match := re.search(r"(-o )(.+?)( |$)", self.cmd): |
| 47 | result = match.group(2) |
| 48 | elif match := re.search(r"[\w._/-]+?\.l?a", self.cmd): |
| 49 | result = match.group(0) |
| 50 | elif match := re.search(r"[\w._/-]+?\.l?(c|cpp|cc)", self.cmd): |
| 51 | result = match.group(0) |
| 52 | result = result[: result.rfind(".")] |
| 53 | result = result + ".o" |
| 54 | result = Path(result) |
| 55 | |
| 56 | return self.abspath(result) if real else result |
| 57 | |
| 58 | def objects(self) -> List[Path]: |
| 59 | tokens = self.cmd.split() |
| 60 | |
| 61 | if self.is_link(): |
| 62 | result = {token for token in tokens if token.endswith(".o")} |
| 63 | else: |
| 64 | try: |
| 65 | idx = tokens.index("-o") |
no outgoing calls
no test coverage detected