• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# # -*- coding: utf-8 -*-
3# Copyright (c) 2021 Huawei Device Co., Ltd.
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import os
17import shutil
18import subprocess
19
20INTERFACE_PATH = "interface/sdk-js"
21OUT_ROOT = "out/sdk-public"
22OUTPATH = os.path.join(OUT_ROOT, "public_interface/sdk-js")
23API_PATH = os.path.join(OUTPATH, "api")
24API_GEN_PATH = os.path.join(OUTPATH, "build-tools/api")
25
26
27def copy_sdk_interface(source_root: str):
28    source = os.path.join(source_root, INTERFACE_PATH)
29    dest = os.path.join(source_root, OUTPATH)
30    if os.path.exists(dest) is False:
31        shutil.copytree(source, dest)
32
33
34def copy_api(source_root: str):
35    source = os.path.join(source_root, API_PATH)
36    dest = os.path.join(source_root, API_GEN_PATH)
37    if os.path.exists(dest) is False:
38        shutil.copytree(source, dest)
39
40
41def convert_permission_method(source_root: str, nodejs: str):
42    permission_convert_dir = os.path.join(OUTPATH, "build-tools", "permissions_converter")
43    permission_convert_tool = os.path.join(permission_convert_dir, "convert.js")
44    config_file = os.path.join("base/global/system_resources/systemres/main", "config.json")
45    permission_gen_path = os.path.join(API_GEN_PATH, "permissions.d.ts")
46
47    tool = os.path.abspath(os.path.join(source_root, permission_convert_tool))
48    nodejs = os.path.abspath(nodejs)
49    config = os.path.abspath(os.path.join(source_root, config_file))
50    output_path = os.path.abspath(os.path.join(source_root, permission_gen_path))
51    process = subprocess.Popen([nodejs, tool, config, output_path], shell=False,
52                        cwd=os.path.abspath(os.path.join(source_root, permission_convert_dir)),
53                        stdout=subprocess.PIPE)
54    process.wait()
55
56
57def replace_sdk_api_dir(source_root: str):
58    source = os.path.join(source_root, API_GEN_PATH, "permissions.d.ts")
59    dest = os.path.join(source_root, API_PATH, "permissions.d.ts")
60    if os.path.exists(dest):
61        os.remove(dest)
62    shutil.copyfile(source, dest)
63
64
65def parse_step(source_root: str, nodejs: str):
66    copy_sdk_interface(source_root)
67    copy_api(source_root)
68    convert_permission_method(source_root, nodejs)
69    replace_sdk_api_dir(source_root)
70
71
72def convert_permissions(root_build_dir: str, node_js: str):
73    parse_step(root_build_dir, node_js)
74
75