An extension that installs a single file that was built by cmake. This isn't technically a `build_ext` style python extension, but there's no dedicated command for installing arbitrary data. It's convenient to use this, though, because it lets us manage the files to install as entries i
| 292 | |
| 293 | |
| 294 | class BuiltFile(_BaseExtension): |
| 295 | """An extension that installs a single file that was built by cmake. |
| 296 | |
| 297 | This isn't technically a `build_ext` style python extension, but there's no |
| 298 | dedicated command for installing arbitrary data. It's convenient to use |
| 299 | this, though, because it lets us manage the files to install as entries in |
| 300 | `ext_modules`. |
| 301 | """ |
| 302 | |
| 303 | def __init__( |
| 304 | self, |
| 305 | src_dir: str, |
| 306 | src_name: str, |
| 307 | dst: str, |
| 308 | dependent_cmake_flags: List[str], |
| 309 | is_executable: bool = False, |
| 310 | is_dynamic_lib: bool = False, |
| 311 | ): |
| 312 | """Initializes a BuiltFile. |
| 313 | |
| 314 | Args: |
| 315 | src_dir: The directory of the file to install, relative to the cmake-out |
| 316 | directory. A placeholder %BUILD_TYPE% will be replaced with the build |
| 317 | type for multi-config generators (like Visual Studio) where the build |
| 318 | output is in a subdirectory named after the build type. For single- |
| 319 | config generators (like Makefile Generators or Ninja), this placeholder |
| 320 | will be removed. |
| 321 | src_name: The name of the file to install |
| 322 | dst: The path to install to, relative to the root of the pip |
| 323 | package. If dst ends in "/", it is treated as a directory. |
| 324 | Otherwise it is treated as a filename. |
| 325 | is_executable: If True, the file is an executable. This is used to |
| 326 | determine the destination filename for executable. |
| 327 | is_dynamic_lib: If True, the file is a dynamic library. This is used |
| 328 | to determine the destination filename for dynamic library. |
| 329 | """ |
| 330 | if is_executable and is_dynamic_lib: |
| 331 | raise ValueError("is_executable and is_dynamic_lib cannot be both True.") |
| 332 | if is_executable: |
| 333 | src_name = get_executable_name(src_name) |
| 334 | elif is_dynamic_lib: |
| 335 | src_name = get_dynamic_lib_name(src_name) |
| 336 | src = os.path.join(src_dir, src_name) |
| 337 | # This is not a real extension, so use a unique name that doesn't look |
| 338 | # like a module path. Some of setuptools's autodiscovery will look for |
| 339 | # extension names with prefixes that match certain module paths. |
| 340 | super().__init__( |
| 341 | src=src, |
| 342 | dst=dst, |
| 343 | name=f"@EXECUTORCH_BuiltFile_{src}:{dst}", |
| 344 | dependent_cmake_flags=dependent_cmake_flags, |
| 345 | ) |
| 346 | |
| 347 | def dst_path(self, installer: "InstallerBuildExt") -> Path: |
| 348 | """Returns the path to the destination file. |
| 349 | |
| 350 | Args: |
| 351 | installer: The InstallerBuildExt instance that is installing the |