• 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 sys
18import subprocess
19import argparse
20
21standard_system_build_dir = os.path.join(os.path.dirname(__file__), os.pardir,
22    os.pardir, 'build', 'scripts', 'util')
23build_dir = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir,
24    os.pardir, os.pardir, os.pardir, 'build', 'maple', 'java', 'util')
25if os.path.exists(standard_system_build_dir):
26    sys.path.append(
27        os.path.join(standard_system_build_dir, os.pardir, os.pardir))
28    from scripts.util import build_utils  # noqa: E402
29if os.path.exists(build_dir):
30    sys.path.append(os.path.join(build_dir, os.pardir, os.pardir, os.pardir))
31    from maple.java.util import build_utils  # noqa: E402
32
33
34def parse_args():
35
36    parser = argparse.ArgumentParser()
37    build_utils.add_depfile_option(parser)
38
39    parser.add_argument('--node', help='path to nodejs exetuable')
40    parser.add_argument('--babel-js', help='path to babel.js')
41    parser.add_argument('--ets-loader-src-dir', help='path to compiler/src')
42    parser.add_argument('--babel-config-js', help='path babel.config.js')
43    parser.add_argument('--uglify-source-js', help='path uglify-source.js')
44    parser.add_argument('--output-dir', help='path to output')
45    parser.add_argument('--declarations-file-dir',
46        help='path declarations file')
47    parser.add_argument('--build-declarations-file-js',
48        help='path build_declarations_file.js')
49    parser.add_argument('--output-declarations-dir',
50        help='path declarations file to output')
51    parser.add_argument('--output-component-config-file',
52        help='path component config file to output')
53    parser.add_argument('--output-form-config-file',
54        help='path form config file to output')
55    parser.add_argument('--kit-configs-file-dir',
56        help='path kit configs file')
57    parser.add_argument('--build-kit-configs-file-js',
58        help='path build_kit_configs_file.js')
59    parser.add_argument('--output-kit-configs-dir',
60        help='path kit configs file to output')
61    parser.add_argument('--kit-apis-file-dir',
62        help='path apis file')
63    parser.add_argument('--arkts-apis-file-dir',
64        help='path apis file')
65    parser.add_argument('--build-public-sdk',
66        help='build public sdk or not')
67
68    options = parser.parse_args()
69    return options
70
71
72def do_build(build_cmd, uglify_cmd, build_declarations_file_cmd, build_kit_configs_file_cmd):
73    for cmd in [build_cmd, uglify_cmd, build_declarations_file_cmd, build_kit_configs_file_cmd]:
74        build_utils.check_output(cmd)
75
76
77def main():
78    options = parse_args()
79    build_cmd = [
80        options.node, options.babel_js, options.ets_loader_src_dir
81    ]
82    build_cmd.extend(['--out-dir', options.output_dir])
83    build_cmd.extend(['--extensions', '.ts'])
84    build_cmd.extend(['--config-file', options.babel_config_js])
85    depfile_deps = [options.node, options.babel_js, options.babel_config_js]
86    depfile_deps.extend(build_utils.get_all_files(options.ets_loader_src_dir))
87
88    uglify_cmd = [options.node, options.uglify_source_js, options.output_dir]
89    depfile_deps.append(options.uglify_source_js)
90
91    build_declarations_file_cmd = [options.node,
92        options.build_declarations_file_js,
93        options.declarations_file_dir,
94        options.output_declarations_dir,
95        options.output_dir,
96        options.build_public_sdk]
97    depfile_deps.append(options.build_declarations_file_js)
98
99    build_kit_configs_file_cmd = [options.node,
100        options.build_kit_configs_file_js,
101        options.kit_configs_file_dir,
102        options.output_kit_configs_dir,
103        options.kit_apis_file_dir,
104        options.arkts_apis_file_dir,
105        options.output_dir]
106    depfile_deps.append(options.build_kit_configs_file_js)
107
108    build_utils.call_and_write_depfile_if_stale(
109        lambda: do_build(build_cmd, uglify_cmd, build_declarations_file_cmd, build_kit_configs_file_cmd),
110        options,
111        depfile_deps=depfile_deps,
112        input_paths=depfile_deps,
113        output_paths=([
114            options.output_dir,
115            options.output_declarations_dir,
116            options.output_component_config_file,
117            options.output_form_config_file,
118            options.output_kit_configs_dir]))
119
120if __name__ == '__main__':
121    sys.exit(main())
122