193fb6ee3Sopenharmony_ci#!/usr/bin/env python 293fb6ee3Sopenharmony_ci# -*- coding: utf-8 -*- 393fb6ee3Sopenharmony_ci# Copyright (c) 2020 Huawei Device Co., Ltd. 493fb6ee3Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License"); 593fb6ee3Sopenharmony_ci# you may not use this file except in compliance with the License. 693fb6ee3Sopenharmony_ci# You may obtain a copy of the License at 793fb6ee3Sopenharmony_ci# 893fb6ee3Sopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0 993fb6ee3Sopenharmony_ci# 1093fb6ee3Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software 1193fb6ee3Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS, 1293fb6ee3Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1393fb6ee3Sopenharmony_ci# See the License for the specific language governing permissions and 1493fb6ee3Sopenharmony_ci# limitations under the License. 1593fb6ee3Sopenharmony_ci 1693fb6ee3Sopenharmony_ciimport os 1793fb6ee3Sopenharmony_ciimport sys 1893fb6ee3Sopenharmony_ciimport subprocess 1993fb6ee3Sopenharmony_ciimport argparse 2093fb6ee3Sopenharmony_ci 2193fb6ee3Sopenharmony_cistandard_system_build_dir = os.path.join(os.path.dirname(__file__), os.pardir, 2293fb6ee3Sopenharmony_ci os.pardir, 'build', 'scripts', 'util') 2393fb6ee3Sopenharmony_cibuild_dir = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, 2493fb6ee3Sopenharmony_ci os.pardir, os.pardir, os.pardir, 'build', 'maple', 'java', 'util') 2593fb6ee3Sopenharmony_ciif os.path.exists(standard_system_build_dir): 2693fb6ee3Sopenharmony_ci sys.path.append( 2793fb6ee3Sopenharmony_ci os.path.join(standard_system_build_dir, os.pardir, os.pardir)) 2893fb6ee3Sopenharmony_ci from scripts.util import build_utils # noqa: E402 2993fb6ee3Sopenharmony_ciif os.path.exists(build_dir): 3093fb6ee3Sopenharmony_ci sys.path.append(os.path.join(build_dir, os.pardir, os.pardir, os.pardir)) 3193fb6ee3Sopenharmony_ci from maple.java.util import build_utils # noqa: E402 3293fb6ee3Sopenharmony_ci 3393fb6ee3Sopenharmony_ci 3493fb6ee3Sopenharmony_cidef parse_args(): 3593fb6ee3Sopenharmony_ci 3693fb6ee3Sopenharmony_ci parser = argparse.ArgumentParser() 3793fb6ee3Sopenharmony_ci build_utils.add_depfile_option(parser) 3893fb6ee3Sopenharmony_ci 3993fb6ee3Sopenharmony_ci parser.add_argument('--node', help='path to nodejs exetuable') 4093fb6ee3Sopenharmony_ci parser.add_argument('--tsc-js', help='path to parse5 module tsc') 4193fb6ee3Sopenharmony_ci parser.add_argument('--parse5-project', help='path to parse5 project') 4293fb6ee3Sopenharmony_ci parser.add_argument('--parse5-output-dir', help='path to parse5 output') 4393fb6ee3Sopenharmony_ci parser.add_argument('--uglify-source-js', help='path uglify-source.js') 4493fb6ee3Sopenharmony_ci 4593fb6ee3Sopenharmony_ci options = parser.parse_args() 4693fb6ee3Sopenharmony_ci return options 4793fb6ee3Sopenharmony_ci 4893fb6ee3Sopenharmony_ci 4993fb6ee3Sopenharmony_cidef do_build(build_cmd, uglify_cmd): 5093fb6ee3Sopenharmony_ci for cmd in [build_cmd, uglify_cmd]: 5193fb6ee3Sopenharmony_ci build_utils.check_output(cmd) 5293fb6ee3Sopenharmony_ci 5393fb6ee3Sopenharmony_ci 5493fb6ee3Sopenharmony_cidef main(): 5593fb6ee3Sopenharmony_ci options = parse_args() 5693fb6ee3Sopenharmony_ci 5793fb6ee3Sopenharmony_ci build_cmd = [ 5893fb6ee3Sopenharmony_ci options.node, options.tsc_js 5993fb6ee3Sopenharmony_ci ] 6093fb6ee3Sopenharmony_ci build_cmd.extend(['--project', options.parse5_project]) 6193fb6ee3Sopenharmony_ci build_cmd.extend(['--outDir', options.parse5_output_dir]) 6293fb6ee3Sopenharmony_ci build_cmd.extend(['--module', 'CommonJS']) 6393fb6ee3Sopenharmony_ci build_cmd.extend(['--target', 'ES6']) 6493fb6ee3Sopenharmony_ci depfile_deps = [options.node, options.tsc_js] 6593fb6ee3Sopenharmony_ci depfile_deps.extend(build_utils.get_all_files(options.parse5_project)) 6693fb6ee3Sopenharmony_ci 6793fb6ee3Sopenharmony_ci uglify_cmd = [options.node, options.uglify_source_js, options.parse5_output_dir] 6893fb6ee3Sopenharmony_ci depfile_deps.append(options.uglify_source_js) 6993fb6ee3Sopenharmony_ci 7093fb6ee3Sopenharmony_ci build_utils.call_and_write_depfile_if_stale( 7193fb6ee3Sopenharmony_ci lambda: do_build(build_cmd, uglify_cmd), 7293fb6ee3Sopenharmony_ci options, 7393fb6ee3Sopenharmony_ci depfile_deps=depfile_deps, 7493fb6ee3Sopenharmony_ci input_paths=depfile_deps, 7593fb6ee3Sopenharmony_ci output_paths=([options.parse5_output_dir])) 7693fb6ee3Sopenharmony_ci 7793fb6ee3Sopenharmony_ci 7893fb6ee3Sopenharmony_ciif __name__ == '__main__': 7993fb6ee3Sopenharmony_ci sys.exit(main()) 80