Skip to content

Commit

Permalink
fix: add codes
Browse files Browse the repository at this point in the history
  • Loading branch information
halajohn committed Oct 14, 2024
1 parent 644e1fb commit 5d4afe2
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
7 changes: 7 additions & 0 deletions build/ten_runtime/feature/publish.gni
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ template("ten_package_publish") {
args += [ "--no-enable-publish" ]
}

args += [
"--os",
target_os,
"--cpu",
target_cpu,
]

args += [
"--log-level",
"${log_level}",
Expand Down
40 changes: 40 additions & 0 deletions build/ten_runtime/feature/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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:
Expand All @@ -35,6 +38,39 @@ def write_published_results_to_file(
file.write(published_results)


def update_manifest(base_dir: str, os_str: str, cpu_str: str) -> 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,
],
check=True,
)
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(
Expand Down Expand Up @@ -62,13 +98,17 @@ 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)

if args.enable_publish is False:
sys.exit(0)

update_manifest(args.base_dir, args.os, args.cpu)

# Use 'tman publish' to perform the uploading.
origin_wd = os.getcwd()

Expand Down
12 changes: 6 additions & 6 deletions tools/supports/update_supports_in_manifest_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,37 @@ def update_supports(input_file: str, output_file: str, os_arch_pairs):
data["supports"] = supports

with open(output_file, "w") as file:
json.dump(data, file, indent=4)
json.dump(data, file, indent=2)

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."
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(
"--os-arch-pairs",
metavar="os/arch",
metavar="os:arch",
type=str,
nargs="+",
help="OS/Arch pairs (e.g., mac/x64 linux/arm)",
help="OS:Arch pairs (e.g., mac:x64 linux:arm)",
)

args = parser.parse_args()

os_arch_pairs = [pair.split("/") for pair in args.os_arch_pairs]
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)}")
print(f"Invalid OS:Arch pair: {':'.join(pair)}")
return

update_supports(args.input_file, args.output_file, os_arch_pairs)
Expand Down

0 comments on commit 5d4afe2

Please sign in to comment.