Build jit_stencils.h in the given directory.
(
self,
*,
comment: str = "",
force: bool = False,
jit_stencils: pathlib.Path,
)
| 231 | return stencil_groups |
| 232 | |
| 233 | def build( |
| 234 | self, |
| 235 | *, |
| 236 | comment: str = "", |
| 237 | force: bool = False, |
| 238 | jit_stencils: pathlib.Path, |
| 239 | ) -> None: |
| 240 | """Build jit_stencils.h in the given directory.""" |
| 241 | jit_stencils.parent.mkdir(parents=True, exist_ok=True) |
| 242 | if not self.stable: |
| 243 | warning = f"JIT support for {self.triple} is still experimental!" |
| 244 | request = "Please report any issues you encounter.".center(len(warning)) |
| 245 | if self.llvm_version != _llvm._LLVM_VERSION: |
| 246 | request = f"Warning! Building with an LLVM version other than {_llvm._LLVM_VERSION} is not supported." |
| 247 | outline = "=" * len(warning) |
| 248 | print("\n".join(["", outline, warning, request, outline, ""])) |
| 249 | digest = f"// {self._compute_digest()}\n" |
| 250 | if ( |
| 251 | not force |
| 252 | and jit_stencils.exists() |
| 253 | and jit_stencils.read_text().startswith(digest) |
| 254 | ): |
| 255 | return |
| 256 | stencil_groups = ASYNCIO_RUNNER.run(self._build_stencils()) |
| 257 | jit_stencils_new = jit_stencils.parent / "jit_stencils.h.new" |
| 258 | try: |
| 259 | with jit_stencils_new.open("w") as file: |
| 260 | file.write(digest) |
| 261 | if comment: |
| 262 | file.write(f"// {comment}\n") |
| 263 | file.write("\n") |
| 264 | for line in _writer.dump(stencil_groups, self.known_symbols): |
| 265 | file.write(f"{line}\n") |
| 266 | try: |
| 267 | jit_stencils_new.replace(jit_stencils) |
| 268 | except FileNotFoundError: |
| 269 | # another process probably already moved the file |
| 270 | if not jit_stencils.is_file(): |
| 271 | raise |
| 272 | finally: |
| 273 | jit_stencils_new.unlink(missing_ok=True) |
| 274 | |
| 275 | |
| 276 | class _COFF( |
no test coverage detected