Skip to content

Commit

Permalink
feat: refine C++ extension standalone test building
Browse files Browse the repository at this point in the history
  • Loading branch information
halajohn committed Jan 12, 2025
1 parent cf1060a commit 28b2426
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 26 deletions.
24 changes: 2 additions & 22 deletions .gnfiles/build/feature/ten_package.gni
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,12 @@ template("ten_package") {
"system",
],
"list lines")

foreach(used_pkg, used_system_pkgs) {
configs += [ "${used_pkg}:config_for_app" ]
}
} else {
pkg_base_dir = get_path_info(_target_name, "dir")

app_base_dir = "${pkg_base_dir}/../../../"

used_system_pkgs =
Expand All @@ -200,29 +200,9 @@ template("ten_package") {
"system",
],
"list lines")
foreach(used_pkg, used_system_pkgs) {
configs += [ "${app_base_dir}${used_pkg}:config_for_ten_packages" ]
}

# =-=-= 拿掉会导致 C++ extension standalone test building fail.
app_base_dir = "${pkg_base_dir}/.ten/app/"

used_system_pkgs = []
used_system_pkgs =
exec_script("//.gnfiles/build/scripts/get_used_ten_pkgs.py",
[
"--pkg-base-dir",
rebase_path("${pkg_base_dir}"),
"--app-base-dir",
rebase_path("${app_base_dir}"),
"--pkg-type",
"system",
],
"list lines")
foreach(used_pkg, used_system_pkgs) {
configs += [
"${app_base_dir}${used_pkg}:config_for_standalone_ten_packages",
]
configs += [ "${app_base_dir}${used_pkg}:config_for_ten_packages" ]
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion .gnfiles/build/feature/ten_package_test.gni
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ template("ten_package_test") {
# Setup relevant variables for the installed system package.
if (invoker.package_kind == "extension") {
pkg_base_dir = get_path_info(_target_name, "dir")
app_base_dir = "${pkg_base_dir}/.ten/app/"
app_base_dir = "${pkg_base_dir}/../../../"

used_system_pkgs =
exec_script("//.gnfiles/build/scripts/get_used_ten_pkgs.py",
Expand All @@ -102,6 +102,7 @@ template("ten_package_test") {
"system",
],
"list lines")

foreach(used_pkg, used_system_pkgs) {
configs +=
[ "${app_base_dir}${used_pkg}:config_for_standalone_ten_packages" ]
Expand Down
40 changes: 37 additions & 3 deletions .gnfiles/build/scripts/get_used_ten_pkgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ def load_manifest_dependencies(pkg_base_dir: str) -> list[dict]:
return []


def load_manifest(path: str) -> dict:
manifest_path = os.path.join(path, "manifest.json")
if os.path.isfile(manifest_path):
with open(manifest_path, "r") as f:
return json.load(f)
return {}


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--app-base-dir", type=str, required=True)
Expand Down Expand Up @@ -78,9 +86,35 @@ def load_manifest_dependencies(pkg_base_dir: str) -> list[dict]:
# Check if the subfolder matches any dependency name and type.
for ten_pkg_dir in ten_pkg_dirs_with_buildgn:
for dep in dependencies:
dep_name = dep.get("name")
dep_type = dep.get("type")

# If 'name' or 'type' is missing but 'path' is present,
# load `manifest.json` to retrieve them.
if not dep_name or not dep_type:
dep_path = dep.get("path")
if dep_path:
combined_path = os.path.join(
args.app_base_dir,
dep_path,
)

# Load `manifest.json` from the specified path.
loaded_manifest = load_manifest(combined_path)
dep_name = loaded_manifest.get("name")
dep_type = loaded_manifest.get("type")
if not dep_name or not dep_type:
# If the necessary information is still
# missing, skip this dependency.
continue
else:
# If there is no 'path' field, skip this
# dependency.
continue

if (
ten_pkg_dir == dep["name"]
and ten_pkg_type_dir == dep["type"]
ten_pkg_dir == dep_name
and ten_pkg_type_dir == dep_type
):
matching_folders.append(
(
Expand All @@ -90,6 +124,6 @@ def load_manifest_dependencies(pkg_base_dir: str) -> list[dict]:
)
)

# Print the matching subfolders.
# Print the matching sub-folders.
for ten_pkg_dir in matching_folders:
print(ten_pkg_dir)

0 comments on commit 28b2426

Please sign in to comment.