16a23e08bSopenharmony_ci#!/usr/bin/env python 26a23e08bSopenharmony_ci# -*- coding: utf-8 -*- 36a23e08bSopenharmony_ci# Copyright (c) 2020 Huawei Device Co., Ltd. 46a23e08bSopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License"); 56a23e08bSopenharmony_ci# you may not use this file except in compliance with the License. 66a23e08bSopenharmony_ci# You may obtain a copy of the License at 76a23e08bSopenharmony_ci# 86a23e08bSopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0 96a23e08bSopenharmony_ci# 106a23e08bSopenharmony_ci# Unless required by applicable law or agreed to in writing, software 116a23e08bSopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS, 126a23e08bSopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 136a23e08bSopenharmony_ci# See the License for the specific language governing permissions and 146a23e08bSopenharmony_ci# limitations under the License. 156a23e08bSopenharmony_ci 166a23e08bSopenharmony_ciimport os 176a23e08bSopenharmony_ciimport sys 186a23e08bSopenharmony_ciimport subprocess 196a23e08bSopenharmony_ciimport argparse 206a23e08bSopenharmony_ci 216a23e08bSopenharmony_cistandard_system_build_dir = os.path.join(os.path.dirname(__file__), os.pardir, 226a23e08bSopenharmony_ci os.pardir, 'build', 'scripts', 'util') 236a23e08bSopenharmony_cibuild_dir = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, 246a23e08bSopenharmony_ci os.pardir, os.pardir, os.pardir, 'build', 'maple', 'java', 'util') 256a23e08bSopenharmony_ciif os.path.exists(standard_system_build_dir): 266a23e08bSopenharmony_ci sys.path.append( 276a23e08bSopenharmony_ci os.path.join(standard_system_build_dir, os.pardir, os.pardir)) 286a23e08bSopenharmony_ci from scripts.util import build_utils # noqa: E402 296a23e08bSopenharmony_ciif os.path.exists(build_dir): 306a23e08bSopenharmony_ci sys.path.append(os.path.join(build_dir, os.pardir, os.pardir, os.pardir)) 316a23e08bSopenharmony_ci from maple.java.util import build_utils # noqa: E402 326a23e08bSopenharmony_ci 336a23e08bSopenharmony_ci 346a23e08bSopenharmony_cidef parse_args(): 356a23e08bSopenharmony_ci 366a23e08bSopenharmony_ci parser = argparse.ArgumentParser() 376a23e08bSopenharmony_ci build_utils.add_depfile_option(parser) 386a23e08bSopenharmony_ci 396a23e08bSopenharmony_ci parser.add_argument('--node', help='path to nodejs exetuable') 406a23e08bSopenharmony_ci parser.add_argument('--babel-js', help='path to babel.js') 416a23e08bSopenharmony_ci parser.add_argument('--ace-loader-src-dir', help='path to ace-loader/src') 426a23e08bSopenharmony_ci parser.add_argument('--babel-config-js', help='path babel.config.js') 436a23e08bSopenharmony_ci parser.add_argument('--module-source-js', help='path module-source.js') 446a23e08bSopenharmony_ci parser.add_argument('--uglify-source-js', help='path uglify-source.js') 456a23e08bSopenharmony_ci parser.add_argument('--output-dir', help='path to output') 466a23e08bSopenharmony_ci 476a23e08bSopenharmony_ci options = parser.parse_args() 486a23e08bSopenharmony_ci return options 496a23e08bSopenharmony_ci 506a23e08bSopenharmony_ci 516a23e08bSopenharmony_cidef do_build(build_cmd, copy_cmd, uglify_cmd): 526a23e08bSopenharmony_ci for cmd in [build_cmd, copy_cmd, uglify_cmd]: 536a23e08bSopenharmony_ci build_utils.check_output(cmd) 546a23e08bSopenharmony_ci 556a23e08bSopenharmony_ci 566a23e08bSopenharmony_cidef main(): 576a23e08bSopenharmony_ci options = parse_args() 586a23e08bSopenharmony_ci build_cmd = [ 596a23e08bSopenharmony_ci options.node, options.babel_js, options.ace_loader_src_dir 606a23e08bSopenharmony_ci ] 616a23e08bSopenharmony_ci build_cmd.extend(['--out-dir', options.output_dir]) 626a23e08bSopenharmony_ci build_cmd.extend(['--config-file', options.babel_config_js]) 636a23e08bSopenharmony_ci depfile_deps = [options.node, options.babel_js, options.babel_config_js] 646a23e08bSopenharmony_ci depfile_deps.extend(build_utils.get_all_files(options.ace_loader_src_dir)) 656a23e08bSopenharmony_ci 666a23e08bSopenharmony_ci copy_cmd = [options.node, options.module_source_js, options.output_dir] 676a23e08bSopenharmony_ci depfile_deps.append(options.module_source_js) 686a23e08bSopenharmony_ci 696a23e08bSopenharmony_ci uglify_cmd = [options.node, options.uglify_source_js, options.output_dir] 706a23e08bSopenharmony_ci depfile_deps.append(options.uglify_source_js) 716a23e08bSopenharmony_ci 726a23e08bSopenharmony_ci build_utils.call_and_write_depfile_if_stale( 736a23e08bSopenharmony_ci lambda: do_build(build_cmd, copy_cmd, uglify_cmd), 746a23e08bSopenharmony_ci options, 756a23e08bSopenharmony_ci depfile_deps=depfile_deps, 766a23e08bSopenharmony_ci input_paths=depfile_deps, 776a23e08bSopenharmony_ci output_paths=([options.output_dir])) 786a23e08bSopenharmony_ci 796a23e08bSopenharmony_ci 806a23e08bSopenharmony_ciif __name__ == '__main__': 816a23e08bSopenharmony_ci sys.exit(main()) 82