|
30 | 30 | err, |
31 | 31 | install_editable, |
32 | 32 | make_cmake_args, |
33 | | - resolve_compilers, |
34 | 33 | run, |
35 | 34 | warn, |
36 | 35 | ) |
37 | 36 |
|
38 | 37 |
|
| 38 | +def find_bin_llvm(compiler_name): |
| 39 | + icx_path = subprocess.check_output(["which", compiler_name]) |
| 40 | + bin_dir = os.path.dirname(icx_path) |
| 41 | + compiler_dir = os.path.join(bin_dir.decode("utf-8"), "compiler") |
| 42 | + if os.path.exists(compiler_dir): |
| 43 | + bin_llvm = compiler_dir |
| 44 | + else: |
| 45 | + bin_dir = os.path.dirname(bin_dir) |
| 46 | + bin_llvm = os.path.join(bin_dir.decode("utf-8"), "bin-llvm") |
| 47 | + assert os.path.exists(bin_llvm) |
| 48 | + return bin_llvm |
| 49 | + |
| 50 | + |
| 51 | +def resolve_compilers( |
| 52 | + oneapi: bool, |
| 53 | + c_compiler: str, |
| 54 | + cxx_compiler: str, |
| 55 | + compiler_root: str, |
| 56 | + bin_llvm: str = None, |
| 57 | +): |
| 58 | + is_linux = "linux" in sys.platform |
| 59 | + |
| 60 | + if oneapi or ( |
| 61 | + c_compiler is None |
| 62 | + and cxx_compiler is None |
| 63 | + and compiler_root is None |
| 64 | + and bin_llvm is None |
| 65 | + ): |
| 66 | + return "icx", ("icpx" if is_linux else "icx"), find_bin_llvm("icx") |
| 67 | + |
| 68 | + if not compiler_root or not os.path.exists(compiler_root): |
| 69 | + raise RuntimeError( |
| 70 | + "--compiler-root option must be set when using non-default DPC++ " |
| 71 | + "layout" |
| 72 | + ) |
| 73 | + |
| 74 | + # default values |
| 75 | + if c_compiler is None: |
| 76 | + c_compiler = "icx" |
| 77 | + if cxx_compiler is None: |
| 78 | + cxx_compiler = "icpx" if is_linux else "icx" |
| 79 | + if bin_llvm is None: |
| 80 | + bin_llvm = find_bin_llvm(c_compiler) |
| 81 | + |
| 82 | + for name, opt_name in ( |
| 83 | + (c_compiler, "--c-compiler"), |
| 84 | + (cxx_compiler, "--cxx-compiler"), |
| 85 | + (bin_llvm, "--bin-llvm"), |
| 86 | + ): |
| 87 | + path = ( |
| 88 | + name if os.path.exists(name) else os.path.join(compiler_root, name) |
| 89 | + ) |
| 90 | + if not os.path.exists(path): |
| 91 | + raise RuntimeError(f"{opt_name} value {name} not found") |
| 92 | + return c_compiler, cxx_compiler, bin_llvm |
| 93 | + |
| 94 | + |
39 | 95 | def parse_args(): |
40 | 96 | p = argparse.ArgumentParser(description="Build dpctl and generate coverage") |
41 | 97 |
|
@@ -140,8 +196,12 @@ def main(): |
140 | 196 | args = parse_args() |
141 | 197 | setup_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
142 | 198 |
|
143 | | - c_compiler, cxx_compiler = resolve_compilers( |
144 | | - args.oneapi, args.c_compiler, args.cxx_compiler, args.compiler_root |
| 199 | + c_compiler, cxx_compiler, bin_llvm = resolve_compilers( |
| 200 | + args.oneapi, |
| 201 | + args.c_compiler, |
| 202 | + args.cxx_compiler, |
| 203 | + args.compiler_root, |
| 204 | + args.bin_llvm, |
145 | 205 | ) |
146 | 206 |
|
147 | 207 | if args.clean: |
@@ -178,16 +238,9 @@ def main(): |
178 | 238 | warn("Ignoring pre-existing CMAKE_ARGS in environment") |
179 | 239 | del env["CMAKE_ARGS"] |
180 | 240 |
|
181 | | - if args.bin_llvm: |
182 | | - env["PATH"] = ":".join((env.get("PATH", ""), args.bin_llvm)) |
183 | | - env["LLVM_TOOLS_HOME"] = args.bin_llvm |
184 | | - llvm_profdata = os.path.join(args.bin_llvm, "llvm-profdata") |
185 | | - llvm_cov = os.path.join(args.bin_llvm, "llvm-cov") |
186 | | - cmake_args += f" -DLLVM_TOOLS_HOME={args.bin_llvm}" |
187 | | - cmake_args += f" -DLLVM_PROFDATA={llvm_profdata}" |
188 | | - cmake_args += f" -DLLVM_COV={llvm_cov}" |
189 | | - # Add LLVMCov_EXE for CMake find_package(LLVMCov) |
190 | | - cmake_args += f" -DLLVMCov_EXE={llvm_cov}" |
| 241 | + if bin_llvm: |
| 242 | + env["PATH"] = ":".join((env.get("PATH", ""), bin_llvm)) |
| 243 | + env["LLVM_TOOLS_HOME"] = bin_llvm |
191 | 244 |
|
192 | 245 | print(f"[gen_coverage] Using CMake args:\n {env['CMAKE_ARGS']}") |
193 | 246 |
|
|
0 commit comments