• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3
4# Copyright (c) 2025 Huawei Device Co., Ltd.
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17import os
18import sys
19import json
20
21sys.path.append(
22    os.path.dirname(os.path.dirname(os.path.dirname(
23        os.path.abspath(__file__)))))
24from scripts.util.file_utils import read_json_file
25
26
27class BootPathCollection():
28
29    @staticmethod
30    def run(dest_path):
31        origin_path = "obj/arkcompiler/ets_frontend/ets2panda/aot/build/config/components/ets_frontend/bootpath.json"
32        fix_order_dict, file_list = BootPathCollection.collect_list(origin_path)
33        directory = os.path.dirname(os.path.join(dest_path, f"framework/bootpath.json"))
34        new_json_file = os.path.join(directory, f"bootpath.json")
35
36        data = {}
37        if os.path.exists(new_json_file):
38            with open(new_json_file, "r", encoding="utf-8") as f:
39                data = json.load(f)
40
41        current_value = data.get("bootpath", "")
42        abc_set = set(current_value.split(":")) if current_value else set()
43        abc_set.update(file_list)
44
45        fix_path = ":".join(str(fix_order_dict.get(key, "")) for key in fix_order_dict.keys() if fix_order_dict.get(key, "") != "")
46        file_path = ":".join(sorted(list(abc_set)))
47        data["bootpath"] = fix_path + ":" + file_path
48
49        os.makedirs(directory, exist_ok=True)
50
51        fd = os.open(new_json_file, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o777)
52        with os.fdopen(fd, "w", encoding="utf-8") as f:
53            json.dump(data, f, indent=4, ensure_ascii=False)
54
55
56    @staticmethod
57    def collect_list(target_out_path):
58        directory = os.path.dirname(target_out_path)
59        # fix order jsons of bootpath.json, and arkoala will be removed here
60        # when bootpath generation is separated from generate static abc
61        fix_order_dict = {
62            "ets2abc_etsstdlib_bootabc_bootpath.json": "",
63            "base_sdk_bootpath.json": "",
64            "ets2abc_commonsdk_bootpath.json": "",
65            "resource_bootpath.json": "",
66            "arkoala_bootpath.json": "/system/framework/arkoala.abc"
67        }
68        rest_file_list = []
69        for root, subdirs, files in os.walk(directory):
70            for _filename in files:
71                if "_bootpath" in _filename and _filename in fix_order_dict:
72                    # target bootpath.json with fixed order, store in fix_order_dict
73                    content = read_json_file(os.path.join(root, _filename))
74                    fix_order_dict[_filename] = content["bootpath"]
75                elif "_bootpath" in _filename:
76                    # other bootpath.json, stores in rest_file_list
77                    content = read_json_file(os.path.join(root, _filename))
78                    rest_file_list.append(content["bootpath"])
79
80        return fix_order_dict, rest_file_list
81
82
83if __name__ == "__main__":
84    pass