Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: refine addon mechanism #19

Merged
merged 2 commits into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading