• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# Copyright (c) 2025 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 argparse
17import os
18import shutil
19import subprocess
20import sys
21import tarfile
22
23
24def copy_files(source_path, dest_path, is_file=False):
25    try:
26        if is_file:
27            os.makedirs(os.path.dirname(dest_path), exist_ok=True)
28            shutil.copy(source_path, dest_path)
29        else:
30            shutil.copytree(source_path, dest_path, dirs_exist_ok=True,
31                symlinks=True)
32    except Exception as err:
33        raise Exception("Copy files failed. Error: " + str(err)) from err
34
35
36def run_cmd(cmd, execution_path=None):
37    proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
38                           stdin=subprocess.PIPE,
39                           stderr=subprocess.PIPE,
40                           cwd=execution_path)
41    stdout, stderr = proc.communicate(timeout=1000)
42    if proc.returncode != 0:
43        raise Exception(stderr.decode())
44
45
46def build(options):
47    build_cmd = [options.npm, 'run', 'compile:plugins']
48    run_cmd(build_cmd, options.source_path)
49
50
51def copy_output(options):
52    run_cmd(['rm', '-rf', options.output_path])
53    copy_files(os.path.join(options.source_path, 'lib'),
54               os.path.join(options.output_path, 'lib'))
55
56    copy_files(os.path.join(options.source_path, '../compiler/components'),
57               os.path.join(options.output_path, 'lib/components'))
58
59    copy_files(os.path.join(options.source_path, 'package.json'),
60               os.path.join(options.output_path, 'package.json'), True)
61
62
63def parse_args():
64    parser = argparse.ArgumentParser()
65    parser.add_argument('--npm', help='path to a npm exetuable')
66    parser.add_argument('--source_path', help='path to build system source')
67    parser.add_argument('--output_path', help='path to output')
68    parser.add_argument('--root_out_dir', help='path to root out')
69    parser.add_argument('--current_os', help='current_os')
70
71    options = parser.parse_args()
72    return options
73
74
75def main():
76    options = parse_args()
77
78    build(options)
79    copy_output(options)
80
81
82if __name__ == '__main__':
83    sys.exit(main())