diff --git a/build/ten_runtime/feature/install_all.py b/build/ten_runtime/feature/install_all.py index 434cee0311..226a668bf7 100644 --- a/build/ten_runtime/feature/install_all.py +++ b/build/ten_runtime/feature/install_all.py @@ -18,6 +18,7 @@ def __init__(self): self.build_type: str self.config_file: str self.log_level: int + self.assume_yes: bool if __name__ == "__main__": @@ -56,6 +57,7 @@ def __init__(self): parser.add_argument( "--log-level", type=int, required=True, help="specify log level" ) + parser.add_argument("--assume-yes", type=bool, default=False) arg_info = ArgumentInfo() args = parser.parse_args(namespace=arg_info) @@ -74,6 +76,9 @@ def __init__(self): if args.config_file is not None: cmd += ["--config-file=" + args.config_file] + if args.assume_yes: + cmd += ["--yes"] + cmd += ["install"] if args.build_type is not None: diff --git a/build/ten_runtime/feature/publish.gni b/build/ten_runtime/feature/publish.gni index 845f3c74a1..41502d8261 100644 --- a/build/ten_runtime/feature/publish.gni +++ b/build/ten_runtime/feature/publish.gni @@ -41,6 +41,13 @@ template("ten_package_publish") { args += [ "--no-enable-publish" ] } + args += [ + "--os", + target_os, + "--cpu", + target_cpu, + ] + args += [ "--log-level", "${log_level}", diff --git a/build/ten_runtime/feature/publish.py b/build/ten_runtime/feature/publish.py index 0675a15dc5..5ee32ca782 100644 --- a/build/ten_runtime/feature/publish.py +++ b/build/ten_runtime/feature/publish.py @@ -10,6 +10,7 @@ import sys from build.scripts import cmd_exec, touch from common.scripts import delete_files +import subprocess class ArgumentInfo(argparse.Namespace): @@ -20,6 +21,8 @@ def __init__(self): self.config_file: str self.log_level: int self.enable_publish: bool + self.os: str + self.cpu: str def extract_publish_path(text: str) -> str | None: @@ -35,8 +38,49 @@ def write_published_results_to_file( file.write(published_results) +def update_manifest( + base_dir: str, os_str: str, cpu_str: str, log_level: int +) -> None: + manifest_path = os.path.join(base_dir, "manifest.json") + + os_arch_pair = f"{os_str}:{cpu_str}" + + script_dir = os.path.dirname(os.path.abspath(__file__)) + update_script_path = os.path.abspath( + os.path.join( + script_dir, + "../../../tools/supports/update_supports_in_manifest_json.py", + ) + ) + + try: + subprocess.run( + [ + "python", + update_script_path, + "--input-file", + manifest_path, + "--output-file", + manifest_path, + "--os-arch-pairs", + os_arch_pair, + "--log-level", + str(log_level), + ], + check=True, + ) + if log_level > 0: + print( + f"Manifest updated successfully with os/cpu: {os_str}/{cpu_str}" + ) + except subprocess.CalledProcessError as e: + print(f"Failed to update manifest.json: {e}") + sys.exit(1) + + if __name__ == "__main__": parser = argparse.ArgumentParser() + parser.add_argument( "--tman-path", type=str, @@ -62,6 +106,8 @@ def write_published_results_to_file( action=argparse.BooleanOptionalAction, default=True, ) + parser.add_argument("--os", type=str, required=True) + parser.add_argument("--cpu", type=str, required=True) arg_info = ArgumentInfo() args = parser.parse_args(namespace=arg_info) @@ -69,6 +115,8 @@ def write_published_results_to_file( if args.enable_publish is False: sys.exit(0) + update_manifest(args.base_dir, args.os, args.cpu, args.log_level) + # Use 'tman publish' to perform the uploading. origin_wd = os.getcwd() diff --git a/build/ten_runtime/feature/test.gni b/build/ten_runtime/feature/test.gni index 7603390760..ab3e998c13 100644 --- a/build/ten_runtime/feature/test.gni +++ b/build/ten_runtime/feature/test.gni @@ -197,6 +197,11 @@ template("ten_package_test_prepare_app") { args += [ "release" ] } + args += [ + "--assume-yes", + "True", + ] + args += [ "--config-file", rebase_path("${root_out_dir}/tests/local_registry/config.json"), @@ -649,6 +654,11 @@ template("ten_package_standalone_pkg") { args += [ "release" ] } + args += [ + "--assume-yes", + "True", + ] + args += [ "--config-file", rebase_path("${root_out_dir}/tests/local_registry/config.json"), diff --git a/core/src/ten_manager/src/cmd/cmd_install.rs b/core/src/ten_manager/src/cmd/cmd_install.rs index e840b7372b..edb56ed350 100644 --- a/core/src/ten_manager/src/cmd/cmd_install.rs +++ b/core/src/ten_manager/src/cmd/cmd_install.rs @@ -768,7 +768,7 @@ pub async fn execute_cmd( &all_existing_local_pkgs, ); - if has_conflict { + if has_conflict && !tman_config.assume_yes { // "y" for continuing to install, "n" for stopping. let ans = Confirm::new( "Warning!!! Some local packages will be overwritten, \ diff --git a/core/src/ten_manager/src/cmd_line.rs b/core/src/ten_manager/src/cmd_line.rs index 3e8da8d3f1..beaced7814 100644 --- a/core/src/ten_manager/src/cmd_line.rs +++ b/core/src/ten_manager/src/cmd_line.rs @@ -88,6 +88,13 @@ fn create_cmd() -> clap::ArgMatches { .help("Enable verbose output") .action(clap::ArgAction::SetTrue), ) + .arg( + Arg::new("ASSUME_YES") + .short('y') + .long("yes") + .help("Automatically answer 'yes' to all prompts") + .action(clap::ArgAction::SetTrue), + ) .subcommand(crate::cmd::cmd_install::create_sub_cmd(&args_cfg)) .subcommand(crate::cmd::cmd_uninstall::create_sub_cmd(&args_cfg)) .subcommand(crate::cmd::cmd_package::create_sub_cmd(&args_cfg)) @@ -107,6 +114,7 @@ pub fn parse_cmd( tman_config.user_token = matches.get_one::("USER_TOKEN").cloned(); tman_config.mi_mode = matches.get_flag("MI"); tman_config.verbose = matches.get_flag("VERBOSE"); + tman_config.assume_yes = matches.get_flag("ASSUME_YES"); match matches.subcommand() { Some(("install", sub_cmd_args)) => crate::cmd::CommandData::Install( diff --git a/core/src/ten_manager/src/config.rs b/core/src/ten_manager/src/config.rs index 2303ba88dc..34b09db164 100644 --- a/core/src/ten_manager/src/config.rs +++ b/core/src/ten_manager/src/config.rs @@ -35,6 +35,7 @@ pub struct TmanConfig { pub mi_mode: bool, pub verbose: bool, + pub assume_yes: bool, } // Determine the config file path based on the platform. @@ -94,5 +95,6 @@ pub fn read_config(config_file_path: &Option) -> TmanConfig { user_token: config_file_content.user_token, mi_mode: false, verbose: false, + assume_yes: false, } } diff --git a/core/src/ten_manager/src/main.rs b/core/src/ten_manager/src/main.rs index 8396b7a9d0..4d00337d34 100644 --- a/core/src/ten_manager/src/main.rs +++ b/core/src/ten_manager/src/main.rs @@ -59,6 +59,7 @@ fn merge(cmd_line: TmanConfig, config_file: TmanConfig) -> TmanConfig { user_token: cmd_line.user_token.or(config_file.user_token), mi_mode: cmd_line.mi_mode, verbose: cmd_line.verbose, + assume_yes: cmd_line.assume_yes, } } diff --git a/tests/ten_runtime/integration/pytest.ini b/tests/ten_runtime/integration/pytest.ini index 83a9a6e542..856f195dad 100644 --- a/tests/ten_runtime/integration/pytest.ini +++ b/tests/ten_runtime/integration/pytest.ini @@ -11,6 +11,8 @@ addopts = --ignore=tests/ten_runtime/integration/python/cpp_app_python/cpp_app_python_app_source/ten_packages/extension/default_extension_python/tests/ --ignore=tests/ten_runtime/integration/python/get_set_prop_python/get_set_prop_python_app/ten_packages/extension/default_extension_python/tests/ --ignore=tests/ten_runtime/integration/python/go_app_python/go_app_python_app/ten_packages/extension/default_extension_python/tests/ + --ignore=tests/ten_runtime/integration/python/go_app_cythonize/go_app_cythonize_app/ten_packages/extension/default_extension_python/tests/ + --ignore=tests/ten_runtime/integration/python/go_app_partially_cythonize/go_app_partially_cythonize_app/ten_packages/extension/default_extension_python/tests/ --ignore=tests/ten_runtime/integration/python/large_json_python/large_json_python_app/ten_packages/extension/default_extension_python/tests/ --ignore=tests/ten_runtime/integration/python/multi_process_python/multi_process_python_app/ten_packages/extension/default_extension_python/tests/ --ignore=tests/ten_runtime/integration/python/multiple_results_python/multiple_results_python_app/ten_packages/extension/default_extension_python/tests/ diff --git a/tools/supports/update_supports_in_manifest_json.py b/tools/supports/update_supports_in_manifest_json.py new file mode 100644 index 0000000000..9233da0fee --- /dev/null +++ b/tools/supports/update_supports_in_manifest_json.py @@ -0,0 +1,80 @@ +# +# Copyright © 2024 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 json +import argparse + + +class ArgumentInfo(argparse.Namespace): + def __init__(self): + self.input_file: str + self.output_file: str + self.log_level: int + self.os_arch_pairs: list[str] + + +def update_supports( + input_file: str, + output_file: str, + os_arch_pairs: list[list[str]], + log_level: int, +): + with open(input_file, "r") as file: + data = json.load(file) + + supports = [{"os": pair[0], "arch": pair[1]} for pair in os_arch_pairs] + + if "supports" in data: + del data["supports"] + + data["supports"] = supports + + with open(output_file, "w") as file: + json.dump(data, file, indent=2) + + if log_level > 0: + print(f"Updated {output_file} with new 'supports' field.") + + +def main(): + parser = argparse.ArgumentParser( + description="Add OS:Arch pairs to the supports field of a JSON file." + ) + + parser.add_argument("--input-file", type=str, help="Input JSON file path") + parser.add_argument("--output-file", type=str, help="Output JSON file path") + parser.add_argument( + "--log-level", type=int, required=False, help="specify log level" + ) + parser.add_argument( + "--os-arch-pairs", + metavar="os:arch", + type=str, + nargs="+", + help="OS:Arch pairs (e.g., mac:x64 linux:arm)", + ) + + arg_info = ArgumentInfo() + args = parser.parse_args(namespace=arg_info) + + os_arch_pairs = [pair.split(":") for pair in args.os_arch_pairs] + + for pair in os_arch_pairs: + if ( + len(pair) != 2 + or pair[0] not in ["linux", "mac", "win"] + or pair[1] not in ["x86", "x64", "arm", "arm64"] + ): + print(f"Invalid OS:Arch pair: {':'.join(pair)}") + return + + update_supports( + args.input_file, args.output_file, os_arch_pairs, args.log_level + ) + + +if __name__ == "__main__": + main()