import os
import sys
import json
sys.path.append(
os.path.dirname(os.path.dirname(os.path.dirname(
os.path.abspath(__file__)))))
from scripts.util.file_utils import read_json_file
class BootPathCollection():
@staticmethod
def run(dest_path):
origin_path = "obj/arkcompiler/ets_frontend/ets2panda/aot/build/config/components/ets_frontend/bootpath.json"
fix_order_dict, file_list = BootPathCollection.collect_list(origin_path)
directory = os.path.dirname(os.path.join(dest_path, f"framework/bootpath.json"))
new_json_file = os.path.join(directory, f"bootpath.json")
data = {}
if os.path.exists(new_json_file):
with open(new_json_file, "r", encoding="utf-8") as f:
data = json.load(f)
current_value = data.get("bootpath", "")
abc_set = set(current_value.split(":")) if current_value else set()
abc_set.update(file_list)
fix_path = ":".join(str(fix_order_dict.get(key, "")) for key in fix_order_dict.keys() if fix_order_dict.get(key, "") != "")
file_path = ":".join(sorted(list(abc_set)))
data["bootpath"] = fix_path + ":" + file_path
os.makedirs(directory, exist_ok=True)
fd = os.open(new_json_file, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o777)
with os.fdopen(fd, "w", encoding="utf-8") as f:
json.dump(data, f, indent=4, ensure_ascii=False)
@staticmethod
def collect_list(target_out_path):
directory = os.path.dirname(target_out_path)
fix_order_dict = {
"ets2abc_etsstdlib_bootabc_bootpath.json": "",
"base_sdk_bootpath.json": "",
"ets2abc_commonsdk_bootpath.json": "",
"resource_bootpath.json": "",
"arkoala_bootpath.json": "/system/framework/arkoala.abc"
}
rest_file_list = []
for root, subdirs, files in os.walk(directory):
for _filename in files:
if "_bootpath" in _filename and _filename in fix_order_dict:
content = read_json_file(os.path.join(root, _filename))
fix_order_dict[_filename] = content["bootpath"]
elif "_bootpath" in _filename:
content = read_json_file(os.path.join(root, _filename))
for value in content["bootpath"].split(":"):
rest_file_list.append(value)
return fix_order_dict, rest_file_list
if __name__ == "__main__":
pass