| 44 | |
| 45 | |
| 46 | def find_profdata(cc: str) -> str: |
| 47 | cc_path = shutil.which(cc) |
| 48 | if cc_path: |
| 49 | cand = os.path.join(os.path.dirname(os.path.realpath(cc_path)), "llvm-profdata") |
| 50 | if os.access(cand, os.X_OK): |
| 51 | return cand |
| 52 | for name in ("llvm-profdata",) + tuple(f"llvm-profdata-{v}" for v in range(30, 13, -1)): |
| 53 | p = shutil.which(name) |
| 54 | if p: |
| 55 | return p |
| 56 | if shutil.which("xcrun"): |
| 57 | res = subprocess.run(["xcrun", "--find", "llvm-profdata"], capture_output=True, text=True, check=False) |
| 58 | if res.returncode == 0 and res.stdout.strip(): |
| 59 | return res.stdout.strip() |
| 60 | sys.exit("memwaste-scaling: llvm-profdata not found next to the compiler or on PATH") |
| 61 | |
| 62 | |
| 63 | def replicate(src: str, dst: str, copies: int) -> int: |