3030 err ,
3131 install_editable ,
3232 make_cmake_args ,
33- resolve_compilers ,
3433 run ,
3534 warn ,
3635)
3736
3837
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+
3995def parse_args ():
4096 p = argparse .ArgumentParser (description = "Build dpctl and generate coverage" )
4197
@@ -140,8 +196,12 @@ def main():
140196 args = parse_args ()
141197 setup_dir = os .path .dirname (os .path .dirname (os .path .abspath (__file__ )))
142198
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 ,
145205 )
146206
147207 if args .clean :
@@ -178,21 +238,14 @@ def main():
178238 warn ("Ignoring pre-existing CMAKE_ARGS in environment" )
179239 del env ["CMAKE_ARGS" ]
180240
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 } "
191-
192- print (f"[gen_coverage] Using CMake args:\n { env ['CMAKE_ARGS' ]} " )
241+ if bin_llvm :
242+ env ["PATH" ] = ":" .join ((env .get ("PATH" , "" ), bin_llvm ))
243+ env ["LLVM_TOOLS_HOME" ] = bin_llvm
193244
194245 env ["CMAKE_ARGS" ] = cmake_args
195246
247+ print (f"[gen_coverage] Using CMake args:\n { env ['CMAKE_ARGS' ]} " )
248+
196249 build_extension (
197250 setup_dir ,
198251 env ,
@@ -242,7 +295,7 @@ def main():
242295
243296 run (
244297 [
245- os .path .join (args . bin_llvm or "" , "llvm-profdata" ),
298+ os .path .join (bin_llvm , "llvm-profdata" ),
246299 "merge" ,
247300 "-sparse" ,
248301 env ["LLVM_PROFILE_FILE" ],
@@ -254,7 +307,7 @@ def main():
254307 with open ("dpctl_pytest.lcov" , "w" ) as fh :
255308 subprocess .check_call (
256309 [
257- os .path .join (args . bin_llvm or "" , "llvm-cov" ),
310+ os .path .join (bin_llvm , "llvm-cov" ),
258311 "export" ,
259312 "-format=lcov" ,
260313 "-ignore-filename-regex=/tmp/icpx*" ,
0 commit comments