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. 15import argparse 16import os 17import runpy 18import sys 19 20DEBUG = False 21 22def find_oem_script(path): 23 for relpath, dirs, files in os.walk(path): 24 if "oem_hook.py" in files: 25 script_path = os.path.join(path, relpath, "oem_hook.py") 26 return os.path.normpath(os.path.abspath(script_path)) 27 return "" 28 29 30def main(): 31 if DEBUG: 32 print("Run oem hook start") 33 34 parser = argparse.ArgumentParser() 35 parser.add_argument('--out_build_file', help='oem build', required=True) 36 args = parser.parse_args() 37 output_file = args.out_build_file 38 if DEBUG: 39 print("output_file:" + output_file) 40 41 hiview_build_path = os.path.split(os.path.realpath(__file__))[0] 42 hiview_path = os.path.realpath(os.path.join(hiview_build_path, "..")) 43 script_path = find_oem_script(hiview_path) 44 globals_args = {'oem_dynamic_deps': [], 'oem_test_deps': []} 45 if script_path.strip() == '': 46 print("Could not find oem hook") 47 else: 48 runpy.run_path(script_path, init_globals=globals_args ,run_name='__main__') 49 if DEBUG: 50 print(globals_args) 51 52 dynamic_info = 'oem_dynamic_deps = [\n%s\n]\n' % (''.join(globals_args.get('oem_dynamic_deps', ''))) 53 test_info = ('oem_test_deps = [\n%s\n]\n' % (''.join(globals_args.get('oem_test_deps', '')))) 54 buff = '%s%s' % (dynamic_info, test_info) 55 out_dir = os.path.dirname(output_file) 56 print('out_dir:' + out_dir) 57 if os.path.isdir(out_dir) is False: 58 os.makedirs(out_dir) 59 with open(output_file, 'w') as file_id: 60 if DEBUG: 61 print(buff) 62 file_id.write(buff) 63 64 if DEBUG: 65 print("Run oem hook end") 66 return 0 67 68 69if __name__ == '__main__': 70 sys.exit(main()) 71