Skip to content

Commit

Permalink
refactor: refine addon mechanism (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
halajohn authored Dec 29, 2024
1 parent 7bc8fc1 commit 73ad5bd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
10 changes: 5 additions & 5 deletions .gnfiles/build/feature/ten_package.gni
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ template("ten_package") {
} else if (invoker.package_kind == "protocol") {
package_output_root_dir =
"${root_out_dir}/ten_packages/protocol/${package_output_root_dir_name}"
} else if (invoker.package_kind == "lang_addon_loader") {
package_output_root_dir = "${root_out_dir}/ten_packages/lang_addon_loader/${package_output_root_dir_name}"
} else if (invoker.package_kind == "extension") {
package_output_root_dir =
"${root_out_dir}/ten_packages/extension/${package_output_root_dir_name}"
} else if (invoker.package_kind == "extension_group") {
package_output_root_dir = "${root_out_dir}/ten_packages/extension_group/${package_output_root_dir_name}"
} else if (invoker.package_kind == "system") {
package_output_root_dir =
"${root_out_dir}/ten_packages/system/${package_output_root_dir_name}"
Expand All @@ -48,8 +48,8 @@ template("ten_package") {
if (invoker.package_kind == "app") {
build_type = "executable"
} else if (invoker.package_kind == "protocol" ||
invoker.package_kind == "lang_addon_loader" ||
invoker.package_kind == "extension" ||
invoker.package_kind == "extension_group" ||
invoker.package_kind == "system") {
build_type = "shared_library"
}
Expand Down Expand Up @@ -295,10 +295,10 @@ template("ten_package") {
"--pkg-type",
"extension",
"--pkg-type",
"extension_group",
"--pkg-type",
"protocol",
"--pkg-type",
"lang_addon_loader",
"--pkg-type",
"system",
],
"list lines")
Expand Down
44 changes: 28 additions & 16 deletions .gnfiles/build/scripts/get_used_ten_pkgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(self):
self.pkg_type: list[str]


def filter_subfolders_with_buildgn(
def filter_folders_with_buildgn(
base_path: str, subfolders: list[str]
) -> list[str]:
folders_with_buildgn = []
Expand Down Expand Up @@ -47,37 +47,49 @@ def load_manifest_dependencies(pkg_base_dir: str) -> list[dict]:

dependencies = load_manifest_dependencies(args.pkg_base_dir)

addon_dirs = {
ten_pkg_type_dirs_info = {
"ten_packages": args.pkg_type,
}

matching_folders = []

for ten_packages, addon_dir in addon_dirs.items():
for subdir in addon_dir:
path = os.path.join(args.app_base_dir, ten_packages, subdir)
for (
ten_packages,
ten_pkg_type_dirs,
) in ten_pkg_type_dirs_info.items():
for ten_pkg_type_dir in ten_pkg_type_dirs:
ten_pkg_type_path = os.path.join(
args.app_base_dir, ten_packages, ten_pkg_type_dir
)

if os.path.isdir(path):
if os.path.isdir(ten_pkg_type_path):
# List all sub-directories in this directory.
subfolders = [
ten_pkg_paths = [
f
for f in os.listdir(path)
if os.path.isdir(os.path.join(path, f))
for f in os.listdir(ten_pkg_type_path)
if os.path.isdir(os.path.join(ten_pkg_type_path, f))
]

# Filter subdirectories that contain a BUILD.gn file.
subfolders_with_buildgn = filter_subfolders_with_buildgn(
path, subfolders
ten_pkg_dirs_with_buildgn = filter_folders_with_buildgn(
ten_pkg_type_path, ten_pkg_paths
)

# Check if the subfolder matches any dependency name and type.
for folder in subfolders_with_buildgn:
for ten_pkg_dir in ten_pkg_dirs_with_buildgn:
for dep in dependencies:
if folder == dep["name"] and subdir == dep["type"]:
if (
ten_pkg_dir == dep["name"]
and ten_pkg_type_dir == dep["type"]
):
matching_folders.append(
f"{ten_packages}/{subdir}/{folder}"
(
f"{ten_packages}/"
f"{ten_pkg_type_dir}/"
f"{ten_pkg_dir}"
)
)

# Print the matching subfolders.
for folder in matching_folders:
print(folder)
for ten_pkg_dir in matching_folders:
print(ten_pkg_dir)

0 comments on commit 73ad5bd

Please sign in to comment.