From c567ae57c03e4e7754bac4712e42d9207036a5c0 Mon Sep 17 00:00:00 2001 From: Hu Yueh-Wei Date: Mon, 20 Jan 2025 17:46:39 +0800 Subject: [PATCH] chore: refine codes a little (#572) --- build/ten_common/general/glob.gni | 10 +++- build/ten_common/general/glob_file.py | 26 +++++++-- build/ten_common/rust/rust.gni | 26 +++++++-- build/ten_runtime/glob.gni | 10 +++- build/ten_runtime/ten.gni | 12 +++- core/src/ten_runtime/BUILD.gn | 35 +++++++++++- core/src/ten_runtime/binding/go/BUILD.gn | 42 ++++++++++++-- .../ten_runtime/binding/go/BUILD_release.gn | 42 -------------- core/src/ten_runtime/binding/nodejs/BUILD.gn | 18 +++++- core/src/ten_runtime/binding/python/BUILD.gn | 41 +++++++++++-- .../binding/python/BUILD_release.gn | 57 ------------------- core/ten_gn | 2 +- .../simple_http_server_go/BUILD.gn | 2 +- 13 files changed, 190 insertions(+), 133 deletions(-) delete mode 100644 core/src/ten_runtime/binding/go/BUILD_release.gn delete mode 100644 core/src/ten_runtime/binding/python/BUILD_release.gn diff --git a/build/ten_common/general/glob.gni b/build/ten_common/general/glob.gni index 039b98b64e..bb753a6b50 100644 --- a/build/ten_common/general/glob.gni +++ b/build/ten_common/general/glob.gni @@ -39,8 +39,14 @@ template("glob") { ] } - sources = - exec_script("//build/ten_common/general/glob_file.py", l, "list lines") + sources_info = + exec_script("//build/ten_common/general/glob_file.py", l, "json") + + sources = [] + foreach(source_info, sources_info) { + sources += [ source_info.path ] + } + if (defined(invoker.sources) && invoker.sources != []) { sources += invoker.sources } diff --git a/build/ten_common/general/glob_file.py b/build/ten_common/general/glob_file.py index 8f4aeb651a..817e096114 100644 --- a/build/ten_common/general/glob_file.py +++ b/build/ten_common/general/glob_file.py @@ -8,28 +8,46 @@ import os import sys import glob +import json class ArgumentInfo(argparse.Namespace): def __init__(self): self.dir: list[str] + self.dir_base: list[str] = [] self.recursive: bool self.only_output_file: bool -def glob_file(dirs: list[str], recursive: bool, only_file: bool) -> None: - for dir in dirs: +def glob_file( + dirs: list[str], dir_bases: list[str], recursive: bool, only_file: bool +) -> None: + output = [] + + for index, dir in enumerate(dirs): + dir_base = dir_bases[index] if index < len(dir_bases) else "" for v in glob.glob(dir, recursive=recursive): if only_file: if not os.path.isfile(v): continue - sys.stdout.write(v.replace("\\", "/") + "\n") + relative_path = os.path.relpath(v, dir_base) if dir_base else "" + + output.append( + { + "path": v.replace("\\", "/"), + "relative_path": relative_path, + } + ) + + json.dump(output, sys.stdout, indent=2) + sys.stdout.write("\n") if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("--dir", type=str, action="append", default=[]) + parser.add_argument("--dir-base", type=str, action="append", default=[]) parser.add_argument("--recursive", action="store_true") # Skip directory in the output. parser.add_argument("--only-output-file", action="store_true") @@ -37,6 +55,6 @@ def glob_file(dirs: list[str], recursive: bool, only_file: bool) -> None: arg_info = ArgumentInfo() args = parser.parse_args(namespace=arg_info) - glob_file(args.dir, args.recursive, args.only_output_file) + glob_file(args.dir, args.dir_base, args.recursive, args.only_output_file) sys.exit(0) diff --git a/build/ten_common/rust/rust.gni b/build/ten_common/rust/rust.gni index 730f887d9e..6afb19d3cd 100644 --- a/build/ten_common/rust/rust.gni +++ b/build/ten_common/rust/rust.gni @@ -143,8 +143,13 @@ template("rust_target") { rebase_path("${invoker.project_path}/**/*.rs"), "--recursive", ], - "list lines") - sources = rust_source_files + "json") + + sources = [] + foreach(rust_source_file, rust_source_files) { + sources += [ rust_source_file.path ] + } + if (defined(invoker.extra_sources)) { sources += invoker.extra_sources } @@ -332,8 +337,13 @@ template("rust_test") { rebase_path("${invoker.project_path}/**/*.rs"), "--recursive", ], - "list lines") - sources = rust_source_files + "json") + + sources = [] + foreach(rust_source_file, rust_source_files) { + sources += [ rust_source_file.path ] + } + if (defined(invoker.extra_sources)) { sources += invoker.extra_sources } @@ -345,9 +355,13 @@ template("rust_test") { rebase_path("${invoker.project_path}/**/Cargo.toml"), "--recursive", ], - "list lines") + "json") + + inputs = [] + foreach(cargo_toml, cargo_tomls) { + inputs += [ cargo_toml.path ] + } - inputs = cargo_tomls if (defined(invoker.extra_inputs)) { inputs += invoker.extra_inputs } diff --git a/build/ten_runtime/glob.gni b/build/ten_runtime/glob.gni index 3c2c4c6b8b..df199f5dbc 100644 --- a/build/ten_runtime/glob.gni +++ b/build/ten_runtime/glob.gni @@ -33,8 +33,14 @@ template("ten_runtime_glob") { ] } - sources = - exec_script("//build/ten_common/general/glob_file.py", l, "list lines") + sources_info = + exec_script("//build/ten_common/general/glob_file.py", l, "json") + + sources = [] + foreach(source_info, sources_info) { + sources += [ source_info.path ] + } + if (defined(invoker.sources)) { sources += invoker.sources } diff --git a/build/ten_runtime/ten.gni b/build/ten_runtime/ten.gni index bad0be0e88..7efa160025 100644 --- a/build/ten_runtime/ten.gni +++ b/build/ten_runtime/ten.gni @@ -223,9 +223,15 @@ template("ten_source_set") { rebase_path(f), ] } - sources = exec_script("//build/ten_common/general/glob_file.py", - rebase_files, - "list lines") + + sources_info = exec_script("//build/ten_common/general/glob_file.py", + rebase_files, + "json") + + foreach(source_info, sources_info) { + sources += [ source_info.path ] + } + if (defined(invoker.sources)) { sources += invoker.sources } diff --git a/core/src/ten_runtime/BUILD.gn b/core/src/ten_runtime/BUILD.gn index dd12853117..9bd2190d30 100644 --- a/core/src/ten_runtime/BUILD.gn +++ b/core/src/ten_runtime/BUILD.gn @@ -93,12 +93,43 @@ ten_package("ten_runtime_system_package") { package_output_root_dir_name = "ten_runtime" resources = [ - "//core/include/ten_runtime=>include/ten_runtime", - "//core/include/ten_utils=>include/ten_utils", "BUILD_release.gn=>BUILD.gn", "manifest.json", ] + runtime_headers = + exec_script("//build/ten_common/general/glob_file.py", + [ + "--dir", + rebase_path("//core/include/ten_runtime/**/*"), + "--dir-base", + rebase_path("//core/include/ten_runtime/"), + "--recursive", + "--only-output-file", + ], + "json") + + foreach(runtime_header, runtime_headers) { + runtime_header_rel_path = runtime_header.relative_path + resources += [ "//core/include/ten_runtime/${runtime_header_rel_path}=>include/ten_runtime/${runtime_header_rel_path}" ] + } + + utils_headers = exec_script("//build/ten_common/general/glob_file.py", + [ + "--dir", + rebase_path("//core/include/ten_utils/**/*"), + "--dir-base", + rebase_path("//core/include/ten_utils/"), + "--recursive", + "--only-output-file", + ], + "json") + + foreach(utils_header, utils_headers) { + utils_header_rel_path = utils_header.relative_path + resources += [ "//core/include/ten_utils/${utils_header_rel_path}=>include/ten_utils/${utils_header_rel_path}" ] + } + foreach(lib, ten_runtime_output_libs) { libname = get_path_info(rebase_path(lib), "file") resources += [ "${lib}=>lib/${libname}" ] diff --git a/core/src/ten_runtime/binding/go/BUILD.gn b/core/src/ten_runtime/binding/go/BUILD.gn index f7fed1f314..be30c72630 100644 --- a/core/src/ten_runtime/binding/go/BUILD.gn +++ b/core/src/ten_runtime/binding/go/BUILD.gn @@ -23,12 +23,42 @@ ten_package("ten_go_binding_system_package") { package_kind = "system" package_output_root_dir_name = "ten_runtime_go" - resources = [ - "//core/src/ten_runtime/binding/go/interface=>interface", - "//core/src/ten_runtime/binding/go/tools=>tools", - "BUILD_release.gn=>BUILD.gn", - "manifest.json", - ] + resources = [ "manifest.json" ] + + interface_files = + exec_script("//build/ten_common/general/glob_file.py", + [ + "--dir", + rebase_path( + "//core/src/ten_runtime/binding/go/interface/**/*"), + "--dir-base", + rebase_path("//core/src/ten_runtime/binding/go/interface/"), + "--recursive", + "--only-output-file", + ], + "json") + + foreach(interface_file, interface_files) { + interface_file_rel_path = interface_file.relative_path + resources += [ "interface/${interface_file_rel_path}=>interface/${interface_file_rel_path}" ] + } + + tools_files = + exec_script("//build/ten_common/general/glob_file.py", + [ + "--dir", + rebase_path("//core/src/ten_runtime/binding/go/tools/**/*"), + "--dir-base", + rebase_path("//core/src/ten_runtime/binding/go/tools/"), + "--recursive", + "--only-output-file", + ], + "json") + + foreach(tool_file, tools_files) { + tool_file_rel_path = tool_file.relative_path + resources += [ "tools/${tool_file_rel_path}=>tools/${tool_file_rel_path}" ] + } foreach(lib, ten_runtime_go_output_libs) { libname = get_path_info(rebase_path(lib), "file") diff --git a/core/src/ten_runtime/binding/go/BUILD_release.gn b/core/src/ten_runtime/binding/go/BUILD_release.gn deleted file mode 100644 index 83a7aa616a..0000000000 --- a/core/src/ten_runtime/binding/go/BUILD_release.gn +++ /dev/null @@ -1,42 +0,0 @@ -# -# Copyright © 2025 Agora -# This file is part of TEN Framework, an open source project. -# Licensed under the Apache License, Version 2.0, with certain conditions. -# Refer to the "LICENSE" file in the root directory for more information. -# -config("ten_runtime_go_common_libs") { - if (is_win) { - libs = [ "ten_runtime_go.dll.lib" ] - } else { - libs = [ "ten_runtime_go" ] - } -} - -config("ten_runtime_go_common_config") { - configs = [ ":ten_runtime_go_common_libs" ] - - include_dirs = [ "//ten_packages/system/ten_runtime_go/include" ] - lib_dirs = [ "//ten_packages/system/ten_runtime_go/lib" ] -} - -config("config_for_app") { - configs = [ ":ten_runtime_go_common_config" ] - - if (is_linux) { - ldflags = - [ "-Wl,-rpath=\$ORIGIN/../ten_packages/system/ten_runtime_go/lib" ] - } else if (is_mac) { - ldflags = - [ "-Wl,-rpath,@loader_path/../ten_packages/system/ten_runtime_go/lib" ] - } -} - -config("config_for_ten_packages") { - configs = [ ":ten_runtime_go_common_config" ] - - if (is_linux) { - ldflags = [ "-Wl,-rpath=\$ORIGIN/../../../system/ten_runtime_go/lib" ] - } else if (is_mac) { - ldflags = [ "-Wl,-rpath,@loader_path/../../../system/ten_runtime_go/lib" ] - } -} diff --git a/core/src/ten_runtime/binding/nodejs/BUILD.gn b/core/src/ten_runtime/binding/nodejs/BUILD.gn index 1cde0b945e..f8024a619c 100644 --- a/core/src/ten_runtime/binding/nodejs/BUILD.gn +++ b/core/src/ten_runtime/binding/nodejs/BUILD.gn @@ -26,12 +26,28 @@ ten_package("ten_nodejs_binding_system_package") { package_output_root_dir_name = "ten_runtime_nodejs" resources = [ - "//core/src/ten_runtime/binding/nodejs/interface=>interface", "manifest.json", "package.json", "tsconfig.json", ] + interface_files = exec_script( + "//build/ten_common/general/glob_file.py", + [ + "--dir", + rebase_path("//core/src/ten_runtime/binding/nodejs/interface/**/*"), + "--dir-base", + rebase_path("//core/src/ten_runtime/binding/nodejs/interface/"), + "--recursive", + "--only-output-file", + ], + "json") + + foreach(interface_file, interface_files) { + interface_file_rel_path = interface_file.relative_path + resources += [ "interface/${interface_file_rel_path}=>interface/${interface_file_rel_path}" ] + } + foreach(lib, ten_runtime_nodejs_output_libs) { libname = get_path_info(rebase_path(lib), "file") resources += [ "${lib}=>lib/${libname}" ] diff --git a/core/src/ten_runtime/binding/python/BUILD.gn b/core/src/ten_runtime/binding/python/BUILD.gn index 92a00271d3..94c1583ff0 100644 --- a/core/src/ten_runtime/binding/python/BUILD.gn +++ b/core/src/ten_runtime/binding/python/BUILD.gn @@ -15,12 +15,41 @@ ten_package("ten_python_binding_system_package") { package_kind = "system" package_output_root_dir_name = "ten_runtime_python" - resources = [ - "//core/src/ten_runtime/binding/python/interface=>interface", - "//core/src/ten_runtime/binding/python/tools=>tools", - "BUILD_release.gn=>BUILD.gn", - "manifest.json", - ] + resources = [ "manifest.json" ] + + interface_files = exec_script( + "//build/ten_common/general/glob_file.py", + [ + "--dir", + rebase_path("//core/src/ten_runtime/binding/python/interface/**/*"), + "--dir-base", + rebase_path("//core/src/ten_runtime/binding/python/interface/"), + "--recursive", + "--only-output-file", + ], + "json") + + foreach(interface_file, interface_files) { + interface_file_rel_path = interface_file.relative_path + resources += [ "interface/${interface_file_rel_path}=>interface/${interface_file_rel_path}" ] + } + + tools_files = exec_script( + "//build/ten_common/general/glob_file.py", + [ + "--dir", + rebase_path("//core/src/ten_runtime/binding/python/tools/**/*"), + "--dir-base", + rebase_path("//core/src/ten_runtime/binding/python/tools/"), + "--recursive", + "--only-output-file", + ], + "json") + + foreach(tool_file, tools_files) { + tool_file_rel_path = tool_file.relative_path + resources += [ "tools/${tool_file_rel_path}=>tools/${tool_file_rel_path}" ] + } foreach(lib, ten_runtime_python_output_libs) { libname = get_path_info(rebase_path(lib), "file") diff --git a/core/src/ten_runtime/binding/python/BUILD_release.gn b/core/src/ten_runtime/binding/python/BUILD_release.gn deleted file mode 100644 index eabccb7afe..0000000000 --- a/core/src/ten_runtime/binding/python/BUILD_release.gn +++ /dev/null @@ -1,57 +0,0 @@ -# -# Copyright © 2025 Agora -# This file is part of TEN Framework, an open source project. -# Licensed under the Apache License, Version 2.0, with certain conditions. -# Refer to the "LICENSE" file in the root directory for more information. -# -import("//build/feature/ten_package.gni") - -config("ten_runtime_python_common_libs") { - if (is_win) { - libs = [ "ten_runtime_python.dll.lib" ] - } else { - libs = [ "ten_runtime_python" ] - } -} - -config("ten_runtime_python_common_config") { - configs = [ ":ten_runtime_python_common_libs" ] - - include_dirs = [ "//ten_packages/system/ten_runtime_python/include" ] - lib_dirs = [ "//ten_packages/system/ten_runtime_python/lib" ] -} - -config("config_for_app") { - configs = [ ":ten_runtime_python_common_config" ] - - if (is_linux) { - ldflags = - [ "-Wl,-rpath=\$ORIGIN/../ten_packages/system/ten_runtime_python/lib" ] - } else if (is_mac) { - ldflags = [ - "-Wl,-rpath,@loader_path/../ten_packages/system/ten_runtime_python/lib", - ] - } -} - -config("config_for_ten_packages") { - configs = [ ":ten_runtime_python_common_config" ] - - if (is_linux) { - ldflags = [ "-Wl,-rpath=\$ORIGIN/../../../system/ten_runtime_python/lib" ] - } else if (is_mac) { - ldflags = - [ "-Wl,-rpath,@loader_path/../../../system/ten_runtime_python/lib" ] - } -} - -ten_package("ten_runtime_python") { - package_kind = "system" - - resources = [ - "interface", - "lib", - "manifest.json", - "tools", - ] -} diff --git a/core/ten_gn b/core/ten_gn index bd725af234..6066ee71db 160000 --- a/core/ten_gn +++ b/core/ten_gn @@ -1 +1 @@ -Subproject commit bd725af234eec5537353701128ba3ef9ac408568 +Subproject commit 6066ee71dbe6f41b45c9c7ad3561e2b4bfb568e2 diff --git a/packages/example_extensions/simple_http_server_go/BUILD.gn b/packages/example_extensions/simple_http_server_go/BUILD.gn index 8de1be3db7..67eea5cd95 100644 --- a/packages/example_extensions/simple_http_server_go/BUILD.gn +++ b/packages/example_extensions/simple_http_server_go/BUILD.gn @@ -12,7 +12,7 @@ ten_package("simple_http_server_go") { package_kind = "extension" resources = [ - "endpoint", + "endpoint/endpoint.go", "go_release.mod=>go.mod", "main.go", "manifest.json",