@@ -63,19 +63,20 @@ def _get_tvm_ffi_includedir() -> str:
6363
6464
6565def _needs_build (source : Path , output : Path ) -> bool :
66- """True if *output* is missing or older than *source*."""
66+ """Check whether *output* is missing or older than *source*."""
6767 if not output .exists ():
6868 return True
6969 return source .stat ().st_mtime > output .stat ().st_mtime
7070
7171
72- def _compile (compiler : str , source : Path , output : Path , flags : list [str ],
73- include_dirs : list [str ]) -> None :
72+ def _compile (
73+ compiler : str , source : Path , output : Path , flags : list [str ], include_dirs : list [str ]
74+ ) -> None :
7475 """Compile *source* → *output*. Skips if cached."""
7576 if not _needs_build (source , output ):
7677 return
7778 output .parent .mkdir (parents = True , exist_ok = True )
78- cmd : list [str ] = [compiler ] + flags
79+ cmd : list [str ] = [compiler , * flags ]
7980 for d in include_dirs :
8081 if compiler in ("cl" , "cl.exe" , "clang-cl" , "clang-cl.exe" ):
8182 cmd .append (f"/I{ d } " )
@@ -165,24 +166,32 @@ def _build_all(llvm_prefix: str) -> None:
165166 clangxx = str (llvm_bin / "clang++" )
166167 _build_variant (
167168 "LLVM Clang" ,
168- c_compiler = clang , cxx_compiler = clangxx ,
169- c_flags = c_flags , cxx_flags = cxx_flags ,
169+ c_compiler = clang ,
170+ cxx_compiler = clangxx ,
171+ c_flags = c_flags ,
172+ cxx_flags = cxx_flags ,
170173 include_dirs = include_dirs ,
171- c_outdir = TESTS_DIR / "c" , cc_outdir = TESTS_DIR / "cc" ,
174+ c_outdir = TESTS_DIR / "c" ,
175+ cc_outdir = TESTS_DIR / "cc" ,
172176 )
173177 if system == "Linux" and shutil .which ("gcc" ):
174178 _build_variant (
175179 "GCC" ,
176- c_compiler = "gcc" , cxx_compiler = "g++" ,
177- c_flags = c_flags , cxx_flags = cxx_flags ,
180+ c_compiler = "gcc" ,
181+ cxx_compiler = "g++" ,
182+ c_flags = c_flags ,
183+ cxx_flags = cxx_flags ,
178184 include_dirs = include_dirs ,
179- c_outdir = TESTS_DIR / "c-gcc" , cc_outdir = TESTS_DIR / "cc-gcc" ,
185+ c_outdir = TESTS_DIR / "c-gcc" ,
186+ cc_outdir = TESTS_DIR / "cc-gcc" ,
180187 )
181188 if system == "Darwin" and Path ("/usr/bin/clang" ).exists ():
182189 _build_variant (
183190 "Apple Clang" ,
184- c_compiler = "/usr/bin/clang" , cxx_compiler = "/usr/bin/clang++" ,
185- c_flags = c_flags , cxx_flags = cxx_flags ,
191+ c_compiler = "/usr/bin/clang" ,
192+ cxx_compiler = "/usr/bin/clang++" ,
193+ c_flags = c_flags ,
194+ cxx_flags = cxx_flags ,
186195 include_dirs = include_dirs ,
187196 c_outdir = TESTS_DIR / "c-appleclang" ,
188197 cc_outdir = TESTS_DIR / "cc-appleclang" ,
@@ -199,28 +208,37 @@ def _build_all(llvm_prefix: str) -> None:
199208 if clang :
200209 _build_variant (
201210 "LLVM Clang" ,
202- c_compiler = clang , cxx_compiler = None ,
203- c_flags = c_flags , cxx_flags = [],
211+ c_compiler = clang ,
212+ cxx_compiler = None ,
213+ c_flags = c_flags ,
214+ cxx_flags = [],
204215 include_dirs = include_dirs ,
205- c_outdir = TESTS_DIR / "c" , cc_outdir = None ,
216+ c_outdir = TESTS_DIR / "c" ,
217+ cc_outdir = None ,
206218 )
207219 # MSVC
208220 if shutil .which ("cl" ):
209221 _build_variant (
210222 "MSVC" ,
211- c_compiler = "cl" , cxx_compiler = None ,
212- c_flags = ["/O2" , "/GS-" ], cxx_flags = [],
223+ c_compiler = "cl" ,
224+ cxx_compiler = None ,
225+ c_flags = ["/O2" , "/GS-" ],
226+ cxx_flags = [],
213227 include_dirs = include_dirs ,
214- c_outdir = TESTS_DIR / "c-msvc" , cc_outdir = None ,
228+ c_outdir = TESTS_DIR / "c-msvc" ,
229+ cc_outdir = None ,
215230 )
216231 # clang-cl
217232 if shutil .which ("clang-cl" ):
218233 _build_variant (
219234 "clang-cl" ,
220- c_compiler = "clang-cl" , cxx_compiler = None ,
221- c_flags = ["/O2" , "/GS-" ], cxx_flags = [],
235+ c_compiler = "clang-cl" ,
236+ cxx_compiler = None ,
237+ c_flags = ["/O2" , "/GS-" ],
238+ cxx_flags = [],
222239 include_dirs = include_dirs ,
223- c_outdir = TESTS_DIR / "c-clang-cl" , cc_outdir = None ,
240+ c_outdir = TESTS_DIR / "c-clang-cl" ,
241+ cc_outdir = None ,
224242 )
225243
226244
@@ -237,7 +255,7 @@ def _build_quickstart(llvm_prefix: str) -> None:
237255 c_flags , cxx_flags = _base_flags (system , machine )
238256 llvm_bin = _find_llvm_bin (llvm_prefix )
239257
240- print (f"\n { '=' * 60 } \n Building quick-start example\n { '=' * 60 } " , flush = True )
258+ print (f"\n { '=' * 60 } \n Building quick-start example\n { '=' * 60 } " , flush = True )
241259
242260 # C variant (all platforms)
243261 c_compiler : str | None = None
@@ -250,16 +268,22 @@ def _build_quickstart(llvm_prefix: str) -> None:
250268
251269 if c_compiler :
252270 _compile (
253- c_compiler , QUICKSTART_DIR / "add_c.c" ,
254- QUICKSTART_DIR / "add_c.o" , c_flags , include_dirs ,
271+ c_compiler ,
272+ QUICKSTART_DIR / "add_c.c" ,
273+ QUICKSTART_DIR / "add_c.o" ,
274+ c_flags ,
275+ include_dirs ,
255276 )
256277
257278 # C++ variant (Linux/macOS only)
258279 if system != "Windows" :
259280 clangxx = str (llvm_bin / "clang++" )
260281 _compile (
261- clangxx , QUICKSTART_DIR / "add.cc" ,
262- QUICKSTART_DIR / "add.o" , cxx_flags , include_dirs ,
282+ clangxx ,
283+ QUICKSTART_DIR / "add.cc" ,
284+ QUICKSTART_DIR / "add.o" ,
285+ cxx_flags ,
286+ include_dirs ,
263287 )
264288
265289
@@ -271,17 +295,22 @@ def _build_quickstart(llvm_prefix: str) -> None:
271295def ensure_built (llvm_prefix : str | None = None ) -> None :
272296 """Build all test objects and quick-start example if needed."""
273297 prefix = llvm_prefix or os .environ .get ("LLVM_PREFIX" , _default_llvm_prefix ())
274- print (f"{ '=' * 60 } \n Building test objects\n { '=' * 60 } " , flush = True )
298+ print (f"{ '=' * 60 } \n Building test objects\n { '=' * 60 } " , flush = True )
275299 _build_all (prefix )
276300 _build_quickstart (prefix )
277- print (f"\n { '=' * 60 } \n All builds completed\n { '=' * 60 } " , flush = True )
301+ print (f"\n { '=' * 60 } \n All builds completed\n { '=' * 60 } " , flush = True )
278302
279303
280304def main () -> None :
281- parser = argparse .ArgumentParser (description = __doc__ ,
282- formatter_class = argparse .RawDescriptionHelpFormatter )
283- parser .add_argument ("--llvm-prefix" , default = None ,
284- help = f"LLVM install prefix (default: { _default_llvm_prefix ()} )" )
305+ """Parse arguments and build all test objects."""
306+ parser = argparse .ArgumentParser (
307+ description = __doc__ , formatter_class = argparse .RawDescriptionHelpFormatter
308+ )
309+ parser .add_argument (
310+ "--llvm-prefix" ,
311+ default = None ,
312+ help = f"LLVM install prefix (default: { _default_llvm_prefix ()} )" ,
313+ )
285314 args = parser .parse_args ()
286315 ensure_built (args .llvm_prefix )
287316
0 commit comments