Skip to content

Commit e4e2995

Browse files
committed
Address comments
Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags:
1 parent 00b6383 commit e4e2995

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

setup.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def __init__(
197197
dst: str,
198198
name: str,
199199
is_cmake_built: bool = True,
200-
is_dst_dir: bool = False,
200+
dst_is_dir: bool = False,
201201
):
202202
# Source path; semantics defined by the subclass.
203203
self.src: str = src
@@ -219,7 +219,7 @@ def __init__(
219219

220220
# If True, the destination is a directory. If False, the destination is a
221221
# file.
222-
self.is_dst_dir: bool = is_dst_dir
222+
self.dst_is_dir: bool = dst_is_dir
223223

224224
super().__init__(name=self.name, sources=[])
225225

@@ -328,29 +328,24 @@ class HeaderFile(_BaseExtension):
328328
def __init__(
329329
self,
330330
src_dir: str,
331-
src_name: Optional[str] = None,
332-
dst_dir: Optional[str] = None,
331+
src_name: str = "*.h",
332+
dst_dir: str = "executorch/include/executorch/",
333333
):
334334
"""Initializes a BuiltFile.
335335
336336
Args:
337337
src_dir: The directory of the headers to install, relative to the root
338-
ExecuTorch source directory. Under the hood, we glob all the headers
339-
using `*.h` patterns.
338+
ExecuTorch source directory. Under the hood, we recursively glob all
339+
the headers using `*.h` patterns.
340340
src_name: The name of the header to install. If not specified, all the
341341
headers in the src_dir will be installed.
342342
dst_dir: The directory to install to, relative to the root of the pip
343-
package. If not specified, defaults to `include/executorch/<src_dir>`.
343+
package. If not specified, defaults to `executorch/include/executorch/`.
344344
"""
345-
if src_name is None:
346-
src_name = "*.h"
347345
src = os.path.join(src_dir, src_name)
348-
if dst_dir is None:
349-
dst = "executorch/include/executorch/"
350-
else:
351-
dst = dst_dir
346+
assert dst_dir.endswith("/"), f"dst_dir must end with '/', got {dst_dir}"
352347
super().__init__(
353-
src=src, dst=dst, name=src_name, is_cmake_built=False, is_dst_dir=True
348+
src=src, dst=dst_dir, name=src_name, is_cmake_built=False, dst_is_dir=True
354349
)
355350

356351
def dst_path(self, installer: "InstallerBuildExt") -> Path:
@@ -429,7 +424,7 @@ def build_extension(self, ext: _BaseExtension) -> None:
429424
# Copy the file.
430425
src_list = src_file.parent.rglob(src_file.name)
431426
for src in src_list:
432-
if ext.is_dst_dir:
427+
if ext.dst_is_dir:
433428
# Destination is a prefix directory. Copy the file to the
434429
# destination directory.
435430
dst = dst_file / src
@@ -438,8 +433,7 @@ def build_extension(self, ext: _BaseExtension) -> None:
438433
dst = dst_file
439434

440435
# Ensure that the destination directory exists.
441-
if not dst.parent.exists():
442-
self.mkpath(os.fspath(dst.parent))
436+
self.mkpath(os.fspath(dst.parent))
443437

444438
self.copy_file(os.fspath(src), os.fspath(dst))
445439

@@ -693,13 +687,18 @@ def get_ext_modules() -> List[Extension]:
693687
ext_modules = []
694688

695689
# Copy all the necessary headers into include/executorch/ so that they can
696-
# be found in the pip package. This is a subset of the headers that are
697-
# essential for building custom ops extensions
690+
# be found in the pip package. This is the subset of headers that are
691+
# essential for building custom ops extensions.
692+
# TODO: Use cmake to gather the headers instead of hard-coding them here.
693+
# For example: https://discourse.cmake.org/t/installing-headers-the-modern-
694+
# way-regurgitated-and-revisited/3238/3
698695
for include_dir in [
699696
"runtime/core/",
700697
"runtime/kernel/",
701698
"runtime/platform/",
702699
"extension/kernel_util/",
700+
"extension/tensor/",
701+
"extension/threadpool/",
703702
]:
704703
ext_modules.append(
705704
HeaderFile(

0 commit comments

Comments
 (0)